I'm planning an API for my own use, in Python. Perhaps someday I will make it freely accessible, but now I'm only planning to use it on my hobby site. At this stage I need some advice on how to set up the URLs, for files that receive both GET and POST requests.
Suppose one of my files is called function_A.py
and used in this fashion:
www.example.com/api/function_A.py?a=something&k=other+thing
My question is, how does one set up 'pretty' URLs in an API, in the least resource-intensive way?
I see most APIs have a typical URL format like http://www.example.com/api/read
instead of http://www.example.com/api/read.py
My options are probably limited to mod_rewrite
v/s urls.py
using Django - or is there another simpler option?
This is for the backend/API and I'd rather keep overhead to a minimum. I only want to handle 4 URLs in this fashion, and do not want to have a regex occur every time the URL is called.
The MYYN is correct. Using a framework such as Ruby on Rails or Django is the easiest way to create a RESTful API.
However, if you don't want to use a framework, you can do the same thing using mod_rewrite in Apache. In fact, this is precisely what most frameworks/applications running on Apache do.
For example, Wordpress uses an .htaccess file like this:
This directs all requests to index.php, where they can be parsed and processed.
Frameworks like RoR or Django do practically the same thing: all requests are redirected to a single file/class/function.