Search code examples
resthateoas

REST API HATEOAS issue


I am reading about HATEOAS in API response, so I have this case, the user will hit this URL first

  1. /payments, this URL will return a list of allowed payment methods, and I am thinking to return a links key which contains the endpoints of those allowed payment methods, but those links need a params should be build/filled by the integrator, is it valid to return HATEOAS in this case, the links are using GET verb.

Thank you,


Solution

  • is it valid to return HATEOAS in this case, the links are using GET verb.

    HATEOAS: your guiding principle is "how would I do it in web pages?"

    In your case, a simple implementation might be that you have a /payments page, and a number of links (pay with paypal, pay by credit card, etc). Each of those links would GET a new web page that had a form on it, that would show the consumer what information was required for that type of payment. Those forms might immediately submit the payment (which would probably be a POST, with the form arguments in the content body), or they would link to a confirmation page (GET, with the form arguments appearing as query parameters), which would show the user a summary of the payment, with a confirm button that would do the POST as before.

    Building a REST api with HATEOAS is the same thing, designed for an program, rather than a person, to consume. So your links key would contain endpoints for the forms of the allowed payment methods, and those forms would appear with a links key that connects the form to the payment methods.