Search code examples
apirestarchitecturehateoas

HATEOAS and client implementation


I have read a few articles about HATEOAS and the way that API should be implemented such that you can traverse to different states by following the links. But I'm confused as to how the client should be implemented?

From this answer:

The client knows nothing about how the server designs its URIs other than what it can find out at runtime.

  • Does the client need to crawl from the root node down to a nested resource to just make a POST if it doesn't know the direct URI?
  • What would be the purpose of API documentation then?

Solution

  • For implementing HATEOAS server needs to include links to responses that goes from server to client, and client uses these links in response to communicate to server.

    For eg. Client request Product list, server will respond with list of products with link to Add, edit and delete the products (if user is able to do that), which will then be transformed in client into links or buttons like Edit Product, Delete Product.

    This blog might help you get more understanding.