When I make a POST request to /api/v1/projects.json
it returns an incorrect Location header. In my opinion, this should point to /api/v1/projects/1
, not /projects/1
, as APIs can then rely on this header to know how to re-locate this object if need be.
Created
January 20, 2011 09:21
-
-
Save radar/787626 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Location"=>"http://example.org/projects/1", # WRONG WRONG WRONG | |
"Content-Type"=>"application/json; charset=utf-8", | |
"Cache-Control"=>"no-cache", | |
"X-UA-Compatible"=>"IE=Edge,chrome=1", | |
"X-Runtime"=>"0.012087" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create | |
project = Project.create(params[:project]) | |
respond_with(project, :location => api_v1_project_path(project) ) | |
end |
apparently the right way to do this is to use sikachu's :location
option. Works for me!
Nope, as it's in the ActionController::Responder
and not in the controller's context. ;)
@sikachu you're right - what I should've said is that you can subclass ActionController::Responder
and override it there. You can then assign your custom responder using self.responder = ApiResponder
in your controller.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can't you override api_location in the controller?