The RestClient is a synchronous HTTP client that offers a modern, fluent API. It offers an abstraction over HTTP libraries that allows for convenient conversion from a Java object to an HTTP request, and the creation of objects from an HTTP response.
Lets see how it is designed.
All interfaces below are defined inside one root interface - RestClient.
/** * Contract for specifying request headers leading up to the exchange. * * @param <S> a self reference to the spec type */ interfaceRequestHeadersSpec<SextendsRequestHeadersSpec<S>> {
S accept(MediaType... acceptableMediaTypes);
S acceptCharset(Charset... acceptableCharsets);
S cookie(String name, String value);
S cookies(Consumer<MultiValueMap<String, String>> cookiesConsumer);
S ifModifiedSince(ZonedDateTime ifModifiedSince);
S ifNoneMatch(String... ifNoneMatches);
S header(String headerName, String... headerValues);
S headers(Consumer<HttpHeaders> headersConsumer);
S apiVersion(Object version);
S attribute(String name, Object value);
S attributes(Consumer<Map<String, Object>> attributesConsumer);
S httpRequest(Consumer<ClientHttpRequest> requestConsumer);
/** * Contract for specifying the URI for a request. * * @param <S> a self reference to the spec type */ interfaceUriSpec<SextendsRequestHeadersSpec<?>> {
S uri(URI uri);
S uri(String uri, @Nullable Object... uriVariables);
S uri(String uri, Map<String, ? extends @Nullable Object> uriVariables);
S uri(String uri, Function<UriBuilder, URI> uriFunction);
S uri(Function<UriBuilder, URI> uriFunction); }
RequestBodySpec
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/** * Contract for specifying request headers and body leading up to the exchange. */ interfaceRequestBodySpecextendsRequestHeadersSpec<RequestBodySpec> {
/** * Contract for specifying request headers and URI for a request. * * @param <S> a self reference to the spec type */ interfaceRequestHeadersUriSpec<SextendsRequestHeadersSpec<S>> extendsUriSpec<S>, RequestHeadersSpec<S> { }
/** * Contract for specifying request headers, body and URI for a request. */ interfaceRequestBodyUriSpecextendsRequestBodySpec, RequestHeadersUriSpec<RequestBodySpec> { }