Api-blueprint: Response without body, description?

Created on 7 Feb 2017  Â·  7Comments  Â·  Source: apiaryio/api-blueprint

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])

Most helpful comment

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

    Received on successful update or insert.

    + Body

Add an empty body.

All 7 comments

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

    Received on successful update or insert.

    + Body

Add an empty body.

@YamiOdymel Thank you sir!

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

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

@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.

@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".

@franklinyu Take a look on responses description:

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

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…

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AlexKorovyansky picture AlexKorovyansky  Â·  4Comments

BigBlueHat picture BigBlueHat  Â·  3Comments

annappropriate picture annappropriate  Â·  5Comments

Perni1984 picture Perni1984  Â·  6Comments

pete001 picture pete001  Â·  6Comments