api2go icon indicating copy to clipboard operation
api2go copied to clipboard

handleRead hardcodes http.StatusOk as status code

Open tochiai opened this issue 9 years ago • 5 comments

It is not possible to set a response status code via the response returned by FindOne; the status code is set to http.StatusOk. Would it be possible to add logic in handleRead to try to use response.StatusCode()?

tochiai avatar Feb 24 '16 20:02 tochiai

The specification of jsonapi only specifies 200 for OK and 404 for not found. http://jsonapi.org/format/#fetching-resources

Could you describe your problem a little bit?

sharpner avatar Feb 24 '16 20:02 sharpner

I was trying to follow this pattern for asynchronous processing http://jsonapi.org/recommendations/#asynchronous-processing

Glossing over some name changes, I'm basically trying to implement the part where a 303 is returned for GET /photos/queue-jobs/5234.

My reading of the spec allows for other status codes when fetching a resource, what do you think? http://jsonapi.org/format/#fetching-resources-responses-other

tochiai avatar Feb 24 '16 22:02 tochiai

you are right, I looked at the code and this is a bug.

Theoretically you should be able to set a status code in the Responder, but in our FindOne method of the api, we always set a 200 which is not right. We have to change this.

wwwdata avatar Feb 24 '16 23:02 wwwdata

Regardless of wether it is a bug or a feature, the next problem will be to implement the "see other" location header. But I'm working on it. If you can live without the self link which is handled in #99 it should be done soon. :-)

sharpner avatar Feb 25 '16 07:02 sharpner

@tochiai I implemented most of the basics in #244 if you want you can test it. But its not yet possible to perfectly implement it.

sharpner avatar Feb 25 '16 18:02 sharpner