Skip to content
This repository has been archived by the owner on Mar 5, 2018. It is now read-only.

Store response for newly created resources #42

Open
mjallday opened this issue Nov 15, 2015 · 4 comments
Open

Store response for newly created resources #42

mjallday opened this issue Nov 15, 2015 · 4 comments

Comments

@mjallday
Copy link

IF I call POST /users I cannot get the result of the initial call if the Location header is set.

This is difficult for me because this call to /users returns a set of credentials for operating on the API and is subsequently needed for authentication.

What's the recommended way to work around this? I see that in the source code the response is discarded if the Location header is set regardless of if there is a body or not.

According to this wikipedia article about the Location header should always be sent on 201 responses.

To provide information about the location of a newly created resource. In this circumstance, the Location header should be sent with an HTTP status code of 201 or 202.

@deontologician
Copy link
Owner

Hey @mjallday currently it just does a redirection automatically. The idea being you aren't really interested in the 201 response, just in the location of the newly created resource. Of course, in real life, you often can't control the api itself, so this behavior is annoying (sorry).

I had a start on a similar issue in #29 but I haven't finished it.

@mjallday
Copy link
Author

Right. What's the thinking with this line? I'm not too familiar with HTTP APIs that don't return a body on a 201. Seems like 202 would be more accurate in this case?

@deontologician
Copy link
Owner

The idea is that a resource has been created, and we want to return you a
navigator pointing to the final resource, instead of to the response to the
creation request. According to the http definition, the body the 201 should
just be links or descriptive properties about the created resource, with
the uri in the location header.

Again, that's the spec, in reality if your api retuns stuff in the 201 body
that you need, rest navigator should let you get at it

On Thu, Nov 19, 2015, 16:30 Marshall Jones notifications@github.com wrote:

Right. What's the thinking with this line
https://github.com/deontologician/restnavigator/blob/next/restnavigator/halnav.py#L550?
I'm not too familiar with HTTP APIs that don't return a body on a 201.
Seems like 202 would be more accurate in this case?


Reply to this email directly or view it on GitHub
#42 (comment)
.

@Skizu
Copy link
Collaborator

Skizu commented Jun 30, 2016

Following on from this, assuming that you're already using an authenticated navigator this should not be an issue. Using the next branch you would simply be able to do the following.

N = restnavigator.Navigator.hal(api, auth=(user, password))
N_new_user = N['users'].create(payload)

Then proceed to use the N_new_user navigator as you please, as although the create will not bind the result, it will fetch the data upon use.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants