Richardson Maturity Model and HATEOAS

Richardson Maturity Level

Richardson Maturity Model Levels for REST APIs

Level 0

Richardson Maturity Level 0

Level 1 — Resources

Richardson Maturity Level 1 — Resources

Level 2 — HTTP Verbs

Richardson Maturity Level 2 — HTTP Verbs

Level 3 — Hypermedia Controls

Richardson Maturity Level 2 — Hypermedia Controls

HATEOAS

GET /accounts/12345 HTTP/1.1
Host: bank.example.com
Accept: application/vnd.acme.account+json
...
HTTP/1.1 200 OK
Content-Type: application/vnd.acme.account+json
Content-Length: ...
{
"account": {
"account_number": 12345,
"balance": {
"currency": "usd",
"value": 100.00
},
"links": {
"deposit": "/accounts/12345/deposit",
"withdraw": "/accounts/12345/withdraw",
"transfer": "/accounts/12345/transfer",
"close": "/accounts/12345/close"
}

}
}
HTTP/1.1 200 OK
Content-Type: application/vnd.acme.account+json
Content-Length: …
{
"account": {
"account_number": 12345,
"balance": {
"currency": "usd",
"value": -25.00
},
"links": {
"deposit": "/accounts/12345/deposit"
}

}
}

To implement HATEOAS in Your Spring Boot Controller

@PostMapping
public ResponseEntity<RestResponse<MappingJacksonValue>>> save(@RequestBody CusCustomerSaveRequestDto cusCustomerSaveRequestDto){

CusCustomerDto cusCustomerDto = cusCustomerService.save(cusCustomerSaveRequestDto);

WebMvcLinkBuilder link = WebMvcLinkBuilder.linkTo(
WebMvcLinkBuilder.methodOn(this.getClass())
.findById(cusCustomerDto.getId()) );
//An EntityModel wraps a domain object and adds links to it. EntityModel entityModel = EntityModel.of(cusCustomerDto);

//Explanation of the link.
entityModel.add(link.withRel("find-by-id"));
//A simple holder for the POJO to serialize with additional serialization instructions to be passed in to the converter. MappingJacksonValue mappingJacksonValue = new MappingJacksonValue(entityModel);


return ResponseEntity.ok(RestResponse.of(mappingJacksonValue));

}
HTTP/1.1 200 OK
Content-Type: application/vnd.acme.account+json
Content-Length: …
{
"data":{
"value": {
"id": 52,
"name": "Yusuf",
"surname": "Memiş",
"identityNo": 12345678901,
"links": [
{
"rel":"find by id",
"href": "http://localhost:8080/api/v1/customer/52"
}

]
},
"responseDate":"2022-02-27T06:26:48,136+00:00",
"messages":null,
"success":true
}
}

References

 by the author.

--

--

--

Çukurova University. A computer engineer who wants to learn more and do better.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Email Sender Application in Python

Go — If/Else, Switch, and For loop

6 steps to improve your web app’s performance

Docker Error: An attempt was made to access a socket in a way forbidden by its access permissions

Hot Jobs in 2021. Apply Now!

Web Traffic: An Important Factor to Consider while Selecting Web Hosting

My Experience at Google CodeU & Google’s Student Retreat

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cahit Barkin Ozer

Cahit Barkin Ozer

Çukurova University. A computer engineer who wants to learn more and do better.

More from Medium

DSA | Cycle detection using Floyd’s algorithm

Spring is an open-source Java framework that you can build powerful applications.

List of Top Decompilers Used by Java Developers

Compiling and running Java Source code using GraalVM and Oracle Java Development Kit