[Solved] Using url.rewrite for routing restful requests? Is there a better option?
Added by dahlke about 6 years ago
This may be way off and a completely stupid idea but...
I was hoping to use url.rewrite to redirect /api/car/"vin-number"/ to a CGI script that could then handle the POST/GET request.
something like this:
url.rewrite-once = (
"^/api/car/([^/?]+)/{0,1}$" => "api/car?vin=$1"
)
That's fine and well until I had a teammate point out that in the eyes of my script I'll end up with a POST request that has a query string. That does seem a little bit odd (maybe it's just me?)
Anywho, is there a better way of handling this? Some kind of routing feature I might have missed? :)
The goal is to be able to handle a request to something like /api/car/"vin-number"/ and then return (or create) that car.
Replies (2)
RE: Using url.rewrite for routing restful requests? Is there a better option? - Added by gstrauss about 6 years ago
Rewriting as you have done looks like it will work, and a query-string is permitted with a POST request, so nothing is wrong there.
Another way to do it is with path-info. If you have /api/car pointed to a script, then the CGI environment will have PATH_INFO=/"vin-number"/... and you can parse that information from PATH_INFO in your CGI script.
RE: Using url.rewrite for routing restful requests? Is there a better option? - Added by dahlke about 6 years ago
PATH_INFO... that's awesome! Thanks so much :)