New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for 'OPTIONS' method when attaching a resource (REST) #45
Comments
|
if I understood you correctly you are looking for $router->add('user.options', '/user')
->addServer(['REQUEST_METHOD' => 'OPTIONS'])
->addValues(['controller' => 'user', 'action' => 'options']);https://github.com/auraphp/Aura.Router/blob/develop-2/src/RouteCollection.php#L242 |
|
Yes, thanks, this what I mean. so I ended up with: this indeed looks more reasonable now. still it's a bit strange I need to handle OPTIONS method here, other methods handled by |
|
oh so what I understood now is you are pointing that in attachResource, the options method is missing. Is that correct ? |
|
If that is the case I think you can send a PR and discuss with @pmjones . ( The code that do the attachResource stuff is at https://github.com/auraphp/Aura.Router/blob/develop-2/src/RouteCollection.php#L460 ) |
add 'options' in attachResource(); fixes #45
While building a RESTful API using router's
attachResource()function I found myself adding a special case for the OPTIONS method as it's not supported by default. It looks something like this:Then in the controller it's simply:
As you can see, I give a response telling the client all methods are allowed. but the reason I had to add this is because for example: Backbone.js by default will first check this method before making any other REST operations with it's models. you can "hack" you way around it in Backbone. but it does not look pretty and actually, why not adding OPTIONS as it's essential part of RESTful services.
I would be glad taking this task on myself, what do you think? does this sound reasonable or am missing something?
The text was updated successfully, but these errors were encountered: