Juneau REST Client
Call REST APIs through typed Java interfaces.
import org.apache.juneau.http.*;
import org.apache.juneau.http.remote.*;
import org.apache.juneau.marshall.json5.*;
import org.apache.juneau.rest.client.*;
@Remote(path="/pets")
public interface PetStore {
@RemoteGet("/{id}")
Pet getPet(@Path("id") long id);
}
RestClient client = RestClient.builder()
.serializer(Json5Serializer.DEFAULT)
.parser(Json5Parser.DEFAULT)
.rootUrl("https://api.example.com")
.build();
PetStore store = client.remote(PetStore.class);
Pet pet = store.getPet(123);
- A fluent client that maps request and response bodies to POJOs.
- Remote proxies: call a REST API through a plain Java interface.
- Pluggable transports: Java’s built-in
HttpClientby default, or Apache HttpClient 4.5 and 5, Jetty and OkHttp. - Tests without a server through
juneau-rest-mock. - The classic client, built on Apache HttpClient, for existing code.
Modules: juneau-rest-client, juneau-rest-client-apache-httpclient-45, juneau-rest-client-apache-httpclient-50, juneau-rest-client-jetty, juneau-rest-client-okhttp, juneau-rest-client-classic