liveBook · Manning

Endpoint

As explained in Quarkus in Action

A REST endpoint is a network-accessible resource interface that handles HTTP interactions according to REST conventions.

A REST endpoint gives a service an HTTP interface. In Quarkus, a Jakarta RESTful Web Services resource class can expose a path and handle a request method. The generated example handles GET /hello and returns plain text. section 2.2.2

Listing 2.4 GreetingResource class: generated sample JAX-RS endpoint
package org.acme;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@Path("/hello")                       #1
public class GreetingResource {

    @GET                                  #2
    @Produces(MediaType.TEXT_PLAIN)       #3
    public String hello() {
        return "Hello from Quarkus REST";    #4
    }
}

The resource class uses @Path to set /hello, @GET to handle the request, and @Produces to declare a plain-text response. section 2.2.2

Test the HTTP behavior rather than only calling the Java method: a Quarkus test sends GET /hello and checks for status 200 and the expected body. An integration test can reuse those checks against the packaged application. section 2.2.2

Listing 2.5 Quarkus test example with REST Assured
package org.acme;

import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;

@QuarkusTest
public class GreetingResourceTest {

    @Test
    public void testHelloEndpoint() {
        given()
          .when().get("/hello")
          .then()
             .statusCode(200)                      #1
             .body(is("Hello from Quarkus REST"));    #2
    }
}

The REST Assured test shows the request and the two response assertions. section 2.2.2

For a reservation service, the endpoint has a more practical job: return cars available between supplied dates and accept a reservation for a car and date range. The quarkus-rest-jackson extension supplies REST functionality with Jackson support for JSON requests and responses. The quarkus-smallrye-openapi extension generates API documentation and a UI for trying endpoints. When running multiple services, configure a different HTTP port to avoid conflicts. section 4.2

A REST endpoint is also a CDI bean without an added CDI annotation. In Dev UI, the Beans page lists it with the default @Singleton scope and offers a link to its source code. section 3.3.1

How Quarkus in Action covers it

How deep it goes
Shows an annotated GET implementation, HTTP test assertions, and extension choices; the generated endpoint handles only one call.
Examples
Uses GET /hello, a test checking status and body, and reservation operations for available cars and bookings.
What it assumes
Assumes familiarity with Java classes and annotations while showing a generated resource as a starting point.
What you can do after
Apply it via Quarkus REST annotations, then test its HTTP response with REST Assured.
How it connects
Connects Jakarta RESTful Web Services, CDI beans, REST Assured testing, Jackson JSON support, and OpenAPI documentation.

Also explained in

Compare how 26 books explain endpoint →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.