Skip to content

Instantly share code, notes, and snippets.

@mikekistler
Last active October 17, 2024 15:10
Show Gist options
  • Save mikekistler/1983a8249c0df56a46f94b4df1b7181d to your computer and use it in GitHub Desktop.
Save mikekistler/1983a8249c0df56a46f94b4df1b7181d to your computer and use it in GitHub Desktop.
Proposal for links in OpenAPI v4
@Bert-R
Copy link

Bert-R commented Jun 4, 2024

The purist approach of HATEOAS is that you figure it all out at runtime. IMHO, that is not realistic.

Your approach allows defining links and the operations they relate to. In a HATEOAS API design, I would use that to define a single public GET operation that returns nothing but a bunch of links. That resource is what the client (e.g. a mobile app) would fetch. The app designers would read what possible links are returned. Then they would read the operations and know the possible subsequent requests. The links would generally be optional and the server will populate those links that are applicable in that actual state of the application.

Such an API design has two major benefits:

  • The app does not need to keep track of the state to know whether a certain operation will be possible. If the operation is possible, its link is available, otherwise not. So, the defined operations are documented in the OAS spec, the subset of actually possible operations is indicated through link availability. E.g. a pageable resource will on the first page not have a previous link, but it will have a next link if multiple pages exist. The next page will have a previous link.
  • The server can change URLs over time without the client being aware (e.g. add a query parameter and populate it from the server, in the the returned link). As long as the operations are the compatible, the app will continue to work.

So, my request to be able to mark operations as "use only through a link" is to guide app designers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment