Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Response without body, description? #381

Open
basickarl opened this issue Feb 7, 2017 · 7 comments
Open

Response without body, description? #381

basickarl opened this issue Feb 7, 2017 · 7 comments

Comments

@basickarl
Copy link

basickarl commented Feb 7, 2017

I'm trying to set a description to a response that does not send a body:

Isn't working:

+ Response 200 (application/vnd.api+json)

    Received on successful update or insert.

This works though:

+ Response 400 (application/vnd.api+json) 

    Received on malformed JSON in the request.

    + Attributes
        - errors (array[Malformed JSON])
@YamiOdymel
Copy link

+ Response 200 (application/vnd.api+json)

    Received on successful update or insert.

    + Body

Add an empty body.

@ixti
Copy link

ixti commented Apr 10, 2017

@YamiOdymel Thank you sir!

Would be awesome to be able avoid such hacks though IMO.

@FranklinYu
Copy link

Strictly speaking, an empty body is not a valid JSON. I use {} instead, but you may prefer null.

@ixti
Copy link

ixti commented Jun 7, 2017

@FranklinYu Empty string is not a valid body for JSON indeed. Strictly speaking, null is not valid JSON either. Valid JSON must have either key/value collection (even empty one, e.g. {}) or a list (also might be empty one, e.g. []).

But, in the issue we are talking about JSON API which allows empty bodies. JSON API utilizes JSON for non empty bodies, but it's NOT JSON. It's scope is wider than just data serialization format.

UPDATE: Somehow information on json.org is a bit misleading, null is a totally valid JSON according to ECMA specs. So any value (object, array, string, number, true, false, null) is a valid top-level citizen of JSON.

@FranklinYu
Copy link

@ixti I have heard of the JSON API but not familiar with it; I skimmed through its specification but didn't find keywords like "empty body".

@ixti
Copy link

ixti commented Jun 7, 2017

@FranklinYu Take a look on responses description:

More than that. You SHOULD NOT send body with 204 response according to HTTP specs as well.

@FranklinYu
Copy link

FranklinYu commented Jun 7, 2017

For empty body in that case, I prefer not to specify content type at all. Clients should not depend on content type in "204 No Content" response. I think I'm getting off topic…

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

4 participants