This presentation provides isights on building HTTP API quickly and efficiently using modern Spring tools. Spring Boot, Spring Data REST and Spring HATEOAS will help achieve the results. It also shows how the application is being built from scratch, with its API being transformed from a primitive CRUD to a fully functional hypermedia style.
A related project can be found at https://github.com/vtsukur/spring-rest-black-market
This presentation by Volodymyr Tsukur (Principal Engineer, GlobalLogic) was delivered at Java Day Lviv on June 14, 2015.
More details: http://globallogic.com.ua/java_day_lviv_2015_presentations
10. 10
Method URL Task
POST /ads Create new ad
GET /ads View ads
GET /ads/{id} Get ad
PATCH / PUT /ads/{id} Update ad
DELETE /ads/{id} Delete ad
CRUD Style API
12. CRUD is NOT enough
if (status == Status.NEW) {
publishedAt = LocalDateTime.now();
status = Status.PUBLISHED;
} …
13. 13
Method URL Task
POST /ads/{id}/publishing Publish ad
POST /ads/{id}/expiration Expire ad
GET /ads/search/published Get published ads
API Changes
17. 17
Task Method URL
Update ad PATCH /ads/{id}
Delete ad DELETE /ads/{id}
Publish ad POST /ads/{id}/publishing
Expire ad POST /ads/{id}/expiration
URI Binding & Construction
18. 18
Task Method URL
Update ad
(only if NEW) PATCH /ads/{id}
Delete ad
(only if NEW) DELETE /ads/{id}
Publish ad
(only if NEW) POST /ads/{id}/publishing
Expire ad
(only if
PUBLISHED)
POST /ads/{id}/expiration
"Figuring" Out the Flow
31. Outcomes -
1. Spring Data REST - simple, CRUD-y
and HATEOAS-y; extensible
PRO TIP: won't solve everything
2. Spring MVC - always there to help
3. Link stuff with Spring HATEOAS
4. Document with Spring REST Docs