Creating the restful endpoints for a microservice
Using the Micronaut framework, we can create all commonly used HTTP methods, namely GET, PUT, POST, and DELETE. At the core, all HTTP concerns are encapsulated in the io.micronaut.http
package. This package contains HttpRequest
and HttpResponse
interfaces. These interfaces are the bedrock of defining any HTTP endpoint. Using these standard implementations, we will cover all HTTP methods in the following sections.
Creating an endpoint for retrieving a list of resources
To create an endpoint for fetching a list of resources, we can begin by adding the com.packtpub.micronaut.web.rest
package to contain all controller resources. We will add a fetch all owners endpoint to the OwnerResource
controller in the pet-owner
microservice:
@Controller("/api") public class OwnerResource { … @Get("/owners") @ExecuteOn(TaskExecutors.IO) ...