Skip to content

Hyper-Schema and non-HTTP-compliant APIs #226

Closed
@handrews

Description

@handrews

HTTP APIs are not necessarily RESTful, and do not necessarily strictly adhere to the official HTTP semantics (most of which are laid out in RFC 7231).

An example is Elasticsearch's use of a request body with GET, where they gleefully interpret the following passage from RFC 7231:

A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request.

to mean "do whatever you want!" which is definitely not what "no defined semantics" is intended to convey. Other examples include many APIs which wrap resource representations in status envelopes in GET responses. The analogous PUT (and other) requests may or may not be wrapped similarly (in the linked API they are not wrapped).

This goes all they way down to APIs that just use POST for everything and always return HTTP 200 even if they have an error.

This topic has come up before in various forms, here is a summary of past discussions:


In PR #179 @Relequestual asserted that we should support these APIs with hyper-schema.

[Only supporting RESTful APIs] would be limiting. [GET with a request body] is not an invalid use of HTTP, it's just not recomended, but there may be valid reasons for doing so.


In issue #88 I had previously asked about this and @awwright commented:

If people can't be bothered to use HTTP correctly in the first place, for what reason would they potentially end up using the hypermedia functionality of JSON Schema?

(then we wandered off into a discussion of JSON Home which is irrelevant, which is why I'm not re-opening that issue).


In issue #107 I asked about response envelopes. Despite also trying to get discussion going by posting about it to the google group, I got zero meaningful responses on the topic. I couldn't figure out a good solution anyway, and #88 had seemed to indicate this shouldn't be supported, so I gave up and closed it.


We need to decide this one way or the other. It has massive implications for what is and isn't out of scope for JSON Hyper-schema.

In particular, "service definition" formats like Swagger/OpenAPI are well-suited to non-RESTful HTTP APIs because they describe every aspect of interaction.

Hyper-schema is not a service definition format, and I strongly believe that it should not become such a thing. While having keywords to help identify and describe HTTP (or other protocol) mis-use would allow very valuable use with a broader range of APIs, I would hate to lose the simplicity that is enabled by proper protocol usage.

Ideally, any features added to support protocol mis-use would be ignorable by hyper-schema authors writing hyper-schemas for properly RESTful APIs.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions