HATEOAS (Hypermedia as the Engine of Application State) is a design principle within RESTful APIs. It dictates that the server dynamically informs the client of available actions and related resources through hypermedia elements embedded within the response.
Imagine you're exploring a choose-your-own-adventure storybook. HATEOAS (Hypermedia as the Engine of Application State) is like the book itself guiding you through the adventure.
How it works:
- You reach a point in the story (like a new level in a game).
- The book (the application) presents you with the available options for what you can do next (like fight a monster or solve a puzzle). These are the hypermedia elements.
- You choose an option by following the provided link or instructions.
- The story then unfolds based on your choice, revealing new options and progressing the state of the application.
{
"orderID":3,
"productID":2,
"quantity":4,
"orderValue":16.60,
"links":[
{
"rel":"customer",
"href":"https://adventure-works.com/customers/3",
"action":"GET",
"types":["text/xml","application/json"]
},
{
"rel":"customer",
"href":"https://adventure-works.com/customers/3",
"action":"PUT",
"types":["application/x-www-form-urlencoded"]
},
{
"rel":"customer",
"href":"https://adventure-works.com/customers/3",
"action":"DELETE",
"types":[]
},
{
"rel":"self",
"href":"https://adventure-works.com/orders/3",
"action":"GET",
"types":["text/xml","application/json"]
},
{
"rel":"self",
"href":"https://adventure-works.com/orders/3",
"action":"PUT",
"types":["application/x-www-form-urlencoded"]
},
{
"rel":"self",
"href":"https://adventure-works.com/orders/3",
"action":"DELETE",
"types":[]
}]
}