Level 3 – Hypermedia Controls

The final level includes having to use Hypermedia As The Engine Of Application State (HATEOASthroughout the process:

As we can see, there is a flow that uses all three levels. The first request goes to the GET URI and gets all of the seats for a specific flight and date. Furthermore, the response is hypermedia-driven. This helps in dynamically navigating the REST interfaces as shown:

# Request
GET http://<HOST>/aircraft/KP3098/seats?date=20182525 HTTP/1.1

The response will be a list of seats that have been flagged as available or not. This is the same as level 1:

# Response

HTTP/1.1 200 OK

{
[
{
"class" : "business",
"seats" : [
{
"number" : "1A",
"status" : "reserved",
"links": [ {
"rel": "self",
"href": "https://<HOST>/aircraft/seats/KP3098/1"
} ]
},
{
"number" : "5A",
"status" : "available",
"links": [ {
"rel": "self",
"href": "https://<HOST>/aircraft/seats/KP3098/15"
} ]
}
]
}
]
}

Now, the next step is to call the endpoint to reserve a seat. We already have the full path to the seat because we want it to be reserved, so we can call the POST method for the specific seat to reserve it:

# Request
POST http://<HOST>/aircraft/KP3098/seats/15 HTTP/1.1

{
"customer-id" : "XOL23423K"
}

The response could be either success or error. This will be followed by the proper HTTP status code, as well as by the full resource that has been created, including its links:

# Response - success case
HTTP/1.1 201 CREATED

{
"customer-id" : "XOL23423K",
"class" : "economic",
"seat" : "18A",
"status" : "reserved",
"links": [ {
"rel": "self",
"href": "https://<HOST>/aircraft/KP3098/seats/15"
} ]
}

The following code snippet is for a failed status:

# Response - error case
HTTP/1.1 409 OK

{
"status" : "failed",
"detail" : "The seat has been selected already"
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.25.32