Writing Business Logic for APIs
You defined API specs using OpenAPI in the previous chapter. API Java interfaces and models were generated by the OpenAPI (Swagger Codegen). In this chapter, you will implement the API’s code in terms of both business logic and data persistence. Here, business logic refers to the actual code you are writing for domain functionalities, which in our case comprise operations performed for e-commerce, such as checking out the shopping cart.
You will write services and repositories for implementation and add hypermedia and entity tags (ETags) to API responses. Hypermedia As The Engine Of Application State (HATEOAS) will be implemented using Spring and Hypertext Application Language (HAL). HAL is one of the standards to implement HATEOAS. Others are Collection+JSON and JSON-LD. You are going to use HAL in this book. You can find a sample of it in the first example in the Adding ETags to API responses section denoted by the "_links"
field...