Chapter 3. Developing RESTful Services
Quarkus integrates with RESTEasy, a JAX-RS implementation to define REST APIs. In this chapter, you’ll learn how to develop RESTful web services in Quarkus. We’ll cover the following topics:
-
How to use JAX-RS for creating CRUD services
-
How to enable CORS for requesting resources from other domains
-
How to implement reactive routes
-
How to implement filters to manipulate requests and responses
3.1 Creating a Simple REST API Endpoint
Problem
You want to create a REST API endpoint with CRUD operations.
Solution
Use the JAX-RS GreetingResource resource generated previously and fill it with JAX-RS annotations.
JAX-RS is the default framework used in Quarkus to define REST endpoints.
All of the JAX-RS annotations are already correctly on your classpath.
You will want to use the HTTP verb annotations (@GET, @POST, @PUT, @DELETE) to declare the HTTP verb(s) that the endpoint methods will listen to.
Of course, you will need the @Path annotation to define the URI relative to the rest of the application for your endpoint.
Open org.acme.quickstart.GreetingResource.java:
packageorg.acme.quickstart;importjavax.ws.rs.GET;importjavax.ws.rs.Path;importjavax.ws.rs.Produces;importjavax.ws.rs.core.MediaType;@Path("/hello")publicclassGreetingResource{@GET@Produces(MediaType.TEXT_PLAIN)publicStringhello(){return"hello" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access