org.springframework.web.client

Class RestTemplate

  • All Implemented Interfaces:
    RestOperations


    public class RestTemplate
    extends InterceptingHttpAccessor
    implements RestOperations
    Synchronous client to perform HTTP requests, exposing a simple, template method API over underlying HTTP client libraries such as the JDK HttpURLConnection, Apache HttpComponents, and others.

    The RestTemplate offers templates for common scenarios by HTTP method, in addition to the generalized exchange and execute methods that support of less frequent cases.

    NOTE: As of 5.0, the non-blocking, reactive org.springframework.web.reactive.client.WebClient offers a modern alternative to the RestTemplate with efficient support for both sync and async, as well as streaming scenarios. The RestTemplate will be deprecated in a future version and will not have major new features added going forward.

    Since:
    3.0
    Author:
    Arjen Poutsma, Brian Clozel, Roy Clarkson, Juergen Hoeller
    See Also:
    HttpMessageConverter, RequestCallback, ResponseExtractor, ResponseErrorHandler
    • Field Summary

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      <T> RequestCallback acceptHeaderRequestCallback(java.lang.Class<T> responseType)
      Return a RequestCallback that sets the request Accept header based on the given response type, cross-checked against the configured message converters.
      void delete(java.lang.String url, java.util.Map<java.lang.String,?> uriVariables)
      Delete the resources at the specified URI.
      void delete(java.lang.String url, java.lang.Object... uriVariables)
      Delete the resources at the specified URI.
      void delete(java.net.URI url)
      Delete the resources at the specified URL.
      protected <T> T doExecute(java.net.URI url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor)
      Execute the given method on the provided URI.
      <T> ResponseEntity<T> exchange(RequestEntity<?> requestEntity, java.lang.Class<T> responseType)
      Execute the request specified in the given RequestEntity and return the response as ResponseEntity.
      <T> ResponseEntity<T> exchange(RequestEntity<?> requestEntity, ParameterizedTypeReference<T> responseType)
      Execute the request specified in the given RequestEntity and return the response as ResponseEntity.
      <T> ResponseEntity<T> exchange(java.lang.String url, HttpMethod method, HttpEntity<?> requestEntity, java.lang.Class<T> responseType, java.util.Map<java.lang.String,?> uriVariables)
      Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.
      <T> ResponseEntity<T> exchange(java.lang.String url, HttpMethod method, HttpEntity<?> requestEntity, java.lang.Class<T> responseType, java.lang.Object... uriVariables)
      Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.
      <T> ResponseEntity<T> exchange(java.lang.String url, HttpMethod method, HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType, java.util.Map<java.lang.String,?> uriVariables)
      Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.
      <T> ResponseEntity<T> exchange(java.lang.String url, HttpMethod method, HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType, java.lang.Object... uriVariables)
      Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.
      <T> ResponseEntity<T> exchange(java.net.URI url, HttpMethod method, HttpEntity<?> requestEntity, java.lang.Class<T> responseType)
      Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.
      <T> ResponseEntity<T> exchange(java.net.URI url, HttpMethod method, HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType)
      Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.
      <T> T execute(java.lang.String url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor, java.util.Map<java.lang.String,?> uriVariables)
      Execute the HTTP method to the given URI template, preparing the request with the RequestCallback, and reading the response with a ResponseExtractor.
      <T> T execute(java.lang.String url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor, java.lang.Object... uriVariables)
      Execute the HTTP method to the given URI template, preparing the request with the RequestCallback, and reading the response with a ResponseExtractor.
      <T> T execute(java.net.URI url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor)
      Execute the HTTP method to the given URL, preparing the request with the RequestCallback, and reading the response with a ResponseExtractor.
      ResponseErrorHandler getErrorHandler()
      Return the error handler.
      <T> ResponseEntity<T> getForEntity(java.lang.String url, java.lang.Class<T> responseType, java.util.Map<java.lang.String,?> uriVariables)
      Retrieve a representation by doing a GET on the URI template.
      <T> ResponseEntity<T> getForEntity(java.lang.String url, java.lang.Class<T> responseType, java.lang.Object... uriVariables)
      Retrieve an entity by doing a GET on the specified URL.
      <T> ResponseEntity<T> getForEntity(java.net.URI url, java.lang.Class<T> responseType)
      Retrieve a representation by doing a GET on the URL .
      <T> T getForObject(java.lang.String url, java.lang.Class<T> responseType, java.util.Map<java.lang.String,?> uriVariables)
      Retrieve a representation by doing a GET on the URI template.
      <T> T getForObject(java.lang.String url, java.lang.Class<T> responseType, java.lang.Object... uriVariables)
      Retrieve a representation by doing a GET on the specified URL.
      <T> T getForObject(java.net.URI url, java.lang.Class<T> responseType)
      Retrieve a representation by doing a GET on the URL .
      java.util.List<HttpMessageConverter<?>> getMessageConverters()
      Return the list of message body converters.
      UriTemplateHandler getUriTemplateHandler()
      Return the configured URI template handler.
      protected void handleResponse(java.net.URI url, HttpMethod method, ClientHttpResponse response)
      Handle the given response, performing appropriate logging and invoking the ResponseErrorHandler if necessary.
      protected ResponseExtractor<HttpHeaders> headersExtractor()
      Return a response extractor for HttpHeaders.
      HttpHeaders headForHeaders(java.lang.String url, java.util.Map<java.lang.String,?> uriVariables)
      Retrieve all headers of the resource specified by the URI template.
      HttpHeaders headForHeaders(java.lang.String url, java.lang.Object... uriVariables)
      Retrieve all headers of the resource specified by the URI template.
      HttpHeaders headForHeaders(java.net.URI url)
      Retrieve all headers of the resource specified by the URL.
      <T> RequestCallback httpEntityCallback(java.lang.Object requestBody)
      Return a RequestCallback implementation that writes the given object to the request stream.
      <T> RequestCallback httpEntityCallback(java.lang.Object requestBody, java.lang.reflect.Type responseType)
      Return a RequestCallback implementation that: Sets the request Accept header based on the given response type, cross-checked against the configured message converters.
      java.util.Set<HttpMethod> optionsForAllow(java.lang.String url, java.util.Map<java.lang.String,?> uriVariables)
      Return the value of the Allow header for the given URI.
      java.util.Set<HttpMethod> optionsForAllow(java.lang.String url, java.lang.Object... uriVariables)
      Return the value of the Allow header for the given URI.
      java.util.Set<HttpMethod> optionsForAllow(java.net.URI url)
      Return the value of the Allow header for the given URL.
      <T> T patchForObject(java.lang.String url, java.lang.Object request, java.lang.Class<T> responseType, java.util.Map<java.lang.String,?> uriVariables)
      Update a resource by PATCHing the given object to the URI template, and return the representation found in the response.
      <T> T patchForObject(java.lang.String url, java.lang.Object request, java.lang.Class<T> responseType, java.lang.Object... uriVariables)
      Update a resource by PATCHing the given object to the URI template, and return the representation found in the response.
      <T> T patchForObject(java.net.URI url, java.lang.Object request, java.lang.Class<T> responseType)
      Update a resource by PATCHing the given object to the URL, and return the representation found in the response.
      <T> ResponseEntity<T> postForEntity(java.lang.String url, java.lang.Object request, java.lang.Class<T> responseType, java.util.Map<java.lang.String,?> uriVariables)
      Create a new resource by POSTing the given object to the URI template, and returns the response as HttpEntity.
      <T> ResponseEntity<T> postForEntity(java.lang.String url, java.lang.Object request, java.lang.Class<T> responseType, java.lang.Object... uriVariables)
      Create a new resource by POSTing the given object to the URI template, and returns the response as ResponseEntity.
      <T> ResponseEntity<T> postForEntity(java.net.URI url, java.lang.Object request, java.lang.Class<T> responseType)
      Create a new resource by POSTing the given object to the URL, and returns the response as ResponseEntity.
      java.net.URI postForLocation(java.lang.String url, java.lang.Object request, java.util.Map<java.lang.String,?> uriVariables)
      Create a new resource by POSTing the given object to the URI template, and returns the value of the Location header.
      java.net.URI postForLocation(java.lang.String url, java.lang.Object request, java.lang.Object... uriVariables)
      Create a new resource by POSTing the given object to the URI template, and returns the value of the Location header.
      java.net.URI postForLocation(java.net.URI url, java.lang.Object request)
      Create a new resource by POSTing the given object to the URL, and returns the value of the Location header.
      <T> T postForObject(java.lang.String url, java.lang.Object request, java.lang.Class<T> responseType, java.util.Map<java.lang.String,?> uriVariables)
      Create a new resource by POSTing the given object to the URI template, and returns the representation found in the response.
      <T> T postForObject(java.lang.String url, java.lang.Object request, java.lang.Class<T> responseType, java.lang.Object... uriVariables)
      Create a new resource by POSTing the given object to the URI template, and returns the representation found in the response.
      <T> T postForObject(java.net.URI url, java.lang.Object request, java.lang.Class<T> responseType)
      Create a new resource by POSTing the given object to the URL, and returns the representation found in the response.
      void put(java.lang.String url, java.lang.Object request, java.util.Map<java.lang.String,?> uriVariables)
      Creates a new resource by PUTting the given object to URI template.
      void put(java.lang.String url, java.lang.Object request, java.lang.Object... uriVariables)
      Create or update a resource by PUTting the given object to the URI.
      void put(java.net.URI url, java.lang.Object request)
      Creates a new resource by PUTting the given object to URL.
      <T> ResponseExtractor<ResponseEntity<T>> responseEntityExtractor(java.lang.reflect.Type responseType)
      Return a ResponseExtractor that prepares a ResponseEntity.
      void setDefaultUriVariables(java.util.Map<java.lang.String,?> uriVars)
      Configure default URI variable values.
      void setErrorHandler(ResponseErrorHandler errorHandler)
      Set the error handler.
      void setMessageConverters(java.util.List<HttpMessageConverter<?>> messageConverters)
      Set the message body converters to use.
      void setUriTemplateHandler(UriTemplateHandler handler)
      Configure a strategy for expanding URI templates.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • setMessageConverters

        public void setMessageConverters(java.util.List<HttpMessageConverter<?>> messageConverters)
        Set the message body converters to use.

        These converters are used to convert from and to HTTP requests and responses.

      • getMessageConverters

        public java.util.List<HttpMessageConverter<?>> getMessageConverters()
        Return the list of message body converters.

        The returned List is active and may get appended to.

      • setDefaultUriVariables

        public void setDefaultUriVariables(java.util.Map<java.lang.String,?> uriVars)
        Configure default URI variable values. This is a shortcut for:
         DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory();
         handler.setDefaultUriVariables(...);
        
         RestTemplate restTemplate = new RestTemplate();
         restTemplate.setUriTemplateHandler(handler);
         
        Parameters:
        uriVars - the default URI variable values
        Since:
        4.3
      • getUriTemplateHandler

        public UriTemplateHandler getUriTemplateHandler()
        Return the configured URI template handler.
      • getForObject

        @Nullable
        public <T> T getForObject(java.lang.String url,
                                            java.lang.Class<T> responseType,
                                            java.lang.Object... uriVariables)
                                     throws RestClientException
        Description copied from interface: RestOperations
        Retrieve a representation by doing a GET on the specified URL. The response (if any) is converted and returned.

        URI Template variables are expanded using the given URI variables, if any.

        Specified by:
        getForObject in interface RestOperations
        Parameters:
        url - the URL
        responseType - the type of the return value
        uriVariables - the variables to expand the template
        Returns:
        the converted object
        Throws:
        RestClientException
      • getForObject

        @Nullable
        public <T> T getForObject(java.lang.String url,
                                            java.lang.Class<T> responseType,
                                            java.util.Map<java.lang.String,?> uriVariables)
                                     throws RestClientException
        Description copied from interface: RestOperations
        Retrieve a representation by doing a GET on the URI template. The response (if any) is converted and returned.

        URI Template variables are expanded using the given map.

        Specified by:
        getForObject in interface RestOperations
        Parameters:
        url - the URL
        responseType - the type of the return value
        uriVariables - the map containing variables for the URI template
        Returns:
        the converted object
        Throws:
        RestClientException
      • getForObject

        @Nullable
        public <T> T getForObject(java.net.URI url,
                                            java.lang.Class<T> responseType)
                                     throws RestClientException
        Description copied from interface: RestOperations
        Retrieve a representation by doing a GET on the URL . The response (if any) is converted and returned.
        Specified by:
        getForObject in interface RestOperations
        Parameters:
        url - the URL
        responseType - the type of the return value
        Returns:
        the converted object
        Throws:
        RestClientException
      • getForEntity

        public <T> ResponseEntity<T> getForEntity(java.lang.String url,
                                                  java.lang.Class<T> responseType,
                                                  java.lang.Object... uriVariables)
                                           throws RestClientException
        Description copied from interface: RestOperations
        Retrieve an entity by doing a GET on the specified URL. The response is converted and stored in an ResponseEntity.

        URI Template variables are expanded using the given URI variables, if any.

        Specified by:
        getForEntity in interface RestOperations
        Parameters:
        url - the URL
        responseType - the type of the return value
        uriVariables - the variables to expand the template
        Returns:
        the entity
        Throws:
        RestClientException
      • getForEntity

        public <T> ResponseEntity<T> getForEntity(java.lang.String url,
                                                  java.lang.Class<T> responseType,
                                                  java.util.Map<java.lang.String,?> uriVariables)
                                           throws RestClientException
        Description copied from interface: RestOperations
        Retrieve a representation by doing a GET on the URI template. The response is converted and stored in an ResponseEntity.

        URI Template variables are expanded using the given map.

        Specified by:
        getForEntity in interface RestOperations
        Parameters:
        url - the URL
        responseType - the type of the return value
        uriVariables - the map containing variables for the URI template
        Returns:
        the converted object
        Throws:
        RestClientException
      • headForHeaders

        public HttpHeaders headForHeaders(java.lang.String url,
                                          java.lang.Object... uriVariables)
                                   throws RestClientException
        Description copied from interface: RestOperations
        Retrieve all headers of the resource specified by the URI template.

        URI Template variables are expanded using the given URI variables, if any.

        Specified by:
        headForHeaders in interface RestOperations
        Parameters:
        url - the URL
        uriVariables - the variables to expand the template
        Returns:
        all HTTP headers of that resource
        Throws:
        RestClientException
      • headForHeaders

        public HttpHeaders headForHeaders(java.lang.String url,
                                          java.util.Map<java.lang.String,?> uriVariables)
                                   throws RestClientException
        Description copied from interface: RestOperations
        Retrieve all headers of the resource specified by the URI template.

        URI Template variables are expanded using the given map.

        Specified by:
        headForHeaders in interface RestOperations
        Parameters:
        url - the URL
        uriVariables - the map containing variables for the URI template
        Returns:
        all HTTP headers of that resource
        Throws:
        RestClientException
      • postForLocation

        @Nullable
        public java.net.URI postForLocation(java.lang.String url,
                                                      @Nullable
                                                      java.lang.Object request,
                                                      java.lang.Object... uriVariables)
                                               throws RestClientException
        Description copied from interface: RestOperations
        Create a new resource by POSTing the given object to the URI template, and returns the value of the Location header. This header typically indicates where the new resource is stored.

        URI Template variables are expanded using the given URI variables, if any.

        The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

        The body of the entity, or request itself, can be a MultiValueMap to create a multipart request. The values in the MultiValueMap can be any Object representing the body of the part, or an HttpEntity representing a part with body and headers. The MultiValueMap can be built conveniently using MultipartBodyBuilder.

        Specified by:
        postForLocation in interface RestOperations
        Parameters:
        url - the URL
        request - the Object to be POSTed (may be null)
        uriVariables - the variables to expand the template
        Returns:
        the value for the Location header
        Throws:
        RestClientException
        See Also:
        HttpEntity
      • postForLocation

        @Nullable
        public java.net.URI postForLocation(java.lang.String url,
                                                      @Nullable
                                                      java.lang.Object request,
                                                      java.util.Map<java.lang.String,?> uriVariables)
                                               throws RestClientException
        Description copied from interface: RestOperations
        Create a new resource by POSTing the given object to the URI template, and returns the value of the Location header. This header typically indicates where the new resource is stored.

        URI Template variables are expanded using the given map.

        The request parameter can be a HttpEntity in order to add additional HTTP headers to the request

        The body of the entity, or request itself, can be a MultiValueMap to create a multipart request. The values in the MultiValueMap can be any Object representing the body of the part, or an HttpEntity representing a part with body and headers. The MultiValueMap can be built conveniently using MultipartBodyBuilder.

        Specified by:
        postForLocation in interface RestOperations
        Parameters:
        url - the URL
        request - the Object to be POSTed (may be null)
        uriVariables - the variables to expand the template
        Returns:
        the value for the Location header
        Throws:
        RestClientException
        See Also:
        HttpEntity
      • postForLocation

        @Nullable
        public java.net.URI postForLocation(java.net.URI url,
                                                      @Nullable
                                                      java.lang.Object request)
                                               throws RestClientException
        Description copied from interface: RestOperations
        Create a new resource by POSTing the given object to the URL, and returns the value of the Location header. This header typically indicates where the new resource is stored.

        The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

        The body of the entity, or request itself, can be a MultiValueMap to create a multipart request. The values in the MultiValueMap can be any Object representing the body of the part, or an HttpEntity representing a part with body and headers. The MultiValueMap can be built conveniently using MultipartBodyBuilder.

        Specified by:
        postForLocation in interface RestOperations
        Parameters:
        url - the URL
        request - the Object to be POSTed (may be null)
        Returns:
        the value for the Location header
        Throws:
        RestClientException
        See Also:
        HttpEntity
      • postForObject

        @Nullable
        public <T> T postForObject(java.lang.String url,
                                             @Nullable
                                             java.lang.Object request,
                                             java.lang.Class<T> responseType,
                                             java.lang.Object... uriVariables)
                                      throws RestClientException
        Description copied from interface: RestOperations
        Create a new resource by POSTing the given object to the URI template, and returns the representation found in the response.

        URI Template variables are expanded using the given URI variables, if any.

        The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

        The body of the entity, or request itself, can be a MultiValueMap to create a multipart request. The values in the MultiValueMap can be any Object representing the body of the part, or an HttpEntity representing a part with body and headers. The MultiValueMap can be built conveniently using MultipartBodyBuilder.

        Specified by:
        postForObject in interface RestOperations
        Parameters:
        url - the URL
        request - the Object to be POSTed (may be null)
        responseType - the type of the return value
        uriVariables - the variables to expand the template
        Returns:
        the converted object
        Throws:
        RestClientException
        See Also:
        HttpEntity
      • postForObject

        @Nullable
        public <T> T postForObject(java.lang.String url,
                                             @Nullable
                                             java.lang.Object request,
                                             java.lang.Class<T> responseType,
                                             java.util.Map<java.lang.String,?> uriVariables)
                                      throws RestClientException
        Description copied from interface: RestOperations
        Create a new resource by POSTing the given object to the URI template, and returns the representation found in the response.

        URI Template variables are expanded using the given map.

        The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

        The body of the entity, or request itself, can be a MultiValueMap to create a multipart request. The values in the MultiValueMap can be any Object representing the body of the part, or an HttpEntity representing a part with body and headers. The MultiValueMap can be built conveniently using MultipartBodyBuilder.

        Specified by:
        postForObject in interface RestOperations
        Parameters:
        url - the URL
        request - the Object to be POSTed (may be null)
        responseType - the type of the return value
        uriVariables - the variables to expand the template
        Returns:
        the converted object
        Throws:
        RestClientException
        See Also:
        HttpEntity
      • postForObject

        @Nullable
        public <T> T postForObject(java.net.URI url,
                                             @Nullable
                                             java.lang.Object request,
                                             java.lang.Class<T> responseType)
                                      throws RestClientException
        Description copied from interface: RestOperations
        Create a new resource by POSTing the given object to the URL, and returns the representation found in the response.

        The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

        The body of the entity, or request itself, can be a MultiValueMap to create a multipart request. The values in the MultiValueMap can be any Object representing the body of the part, or an HttpEntity representing a part with body and headers. The MultiValueMap can be built conveniently using MultipartBodyBuilder.

        Specified by:
        postForObject in interface RestOperations
        Parameters:
        url - the URL
        request - the Object to be POSTed (may be null)
        responseType - the type of the return value
        Returns:
        the converted object
        Throws:
        RestClientException
        See Also:
        HttpEntity
      • postForEntity

        public <T> ResponseEntity<T> postForEntity(java.lang.String url,
                                                   @Nullable
                                                   java.lang.Object request,
                                                   java.lang.Class<T> responseType,
                                                   java.lang.Object... uriVariables)
                                            throws RestClientException
        Description copied from interface: RestOperations
        Create a new resource by POSTing the given object to the URI template, and returns the response as ResponseEntity.

        URI Template variables are expanded using the given URI variables, if any.

        The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

        The body of the entity, or request itself, can be a MultiValueMap to create a multipart request. The values in the MultiValueMap can be any Object representing the body of the part, or an HttpEntity representing a part with body and headers. The MultiValueMap can be built conveniently using MultipartBodyBuilder.

        Specified by:
        postForEntity in interface RestOperations
        Parameters:
        url - the URL
        request - the Object to be POSTed (may be null)
        uriVariables - the variables to expand the template
        Returns:
        the converted object
        Throws:
        RestClientException
        See Also:
        HttpEntity
      • postForEntity

        public <T> ResponseEntity<T> postForEntity(java.lang.String url,
                                                   @Nullable
                                                   java.lang.Object request,
                                                   java.lang.Class<T> responseType,
                                                   java.util.Map<java.lang.String,?> uriVariables)
                                            throws RestClientException
        Description copied from interface: RestOperations
        Create a new resource by POSTing the given object to the URI template, and returns the response as HttpEntity.

        URI Template variables are expanded using the given map.

        The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

        The body of the entity, or request itself, can be a MultiValueMap to create a multipart request. The values in the MultiValueMap can be any Object representing the body of the part, or an HttpEntity representing a part with body and headers. The MultiValueMap can be built conveniently using MultipartBodyBuilder.

        Specified by:
        postForEntity in interface RestOperations
        Parameters:
        url - the URL
        request - the Object to be POSTed (may be null)
        uriVariables - the variables to expand the template
        Returns:
        the converted object
        Throws:
        RestClientException
        See Also:
        HttpEntity
      • postForEntity

        public <T> ResponseEntity<T> postForEntity(java.net.URI url,
                                                   @Nullable
                                                   java.lang.Object request,
                                                   java.lang.Class<T> responseType)
                                            throws RestClientException
        Description copied from interface: RestOperations
        Create a new resource by POSTing the given object to the URL, and returns the response as ResponseEntity.

        The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

        The body of the entity, or request itself, can be a MultiValueMap to create a multipart request. The values in the MultiValueMap can be any Object representing the body of the part, or an HttpEntity representing a part with body and headers. The MultiValueMap can be built conveniently using MultipartBodyBuilder.

        Specified by:
        postForEntity in interface RestOperations
        Parameters:
        url - the URL
        request - the Object to be POSTed (may be null)
        Returns:
        the converted object
        Throws:
        RestClientException
        See Also:
        HttpEntity
      • put

        public void put(java.lang.String url,
                        @Nullable
                        java.lang.Object request,
                        java.lang.Object... uriVariables)
                 throws RestClientException
        Description copied from interface: RestOperations
        Create or update a resource by PUTting the given object to the URI.

        URI Template variables are expanded using the given URI variables, if any.

        The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

        Specified by:
        put in interface RestOperations
        Parameters:
        url - the URL
        request - the Object to be PUT (may be null)
        uriVariables - the variables to expand the template
        Throws:
        RestClientException
        See Also:
        HttpEntity
      • put

        public void put(java.lang.String url,
                        @Nullable
                        java.lang.Object request,
                        java.util.Map<java.lang.String,?> uriVariables)
                 throws RestClientException
        Description copied from interface: RestOperations
        Creates a new resource by PUTting the given object to URI template.

        URI Template variables are expanded using the given map.

        The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.

        Specified by:
        put in interface RestOperations
        Parameters:
        url - the URL
        request - the Object to be PUT (may be null)
        uriVariables - the variables to expand the template
        Throws:
        RestClientException
        See Also:
        HttpEntity
      • delete

        public void delete(java.lang.String url,
                           java.lang.Object... uriVariables)
                    throws RestClientException
        Description copied from interface: RestOperations
        Delete the resources at the specified URI.

        URI Template variables are expanded using the given URI variables, if any.

        Specified by:
        delete in interface RestOperations
        Parameters:
        url - the URL
        uriVariables - the variables to expand in the template
        Throws:
        RestClientException
      • delete

        public void delete(java.lang.String url,
                           java.util.Map<java.lang.String,?> uriVariables)
                    throws RestClientException
        Description copied from interface: RestOperations
        Delete the resources at the specified URI.

        URI Template variables are expanded using the given map.

        Specified by:
        delete in interface RestOperations
        Parameters:
        url - the URL
        uriVariables - the variables to expand the template
        Throws:
        RestClientException
      • optionsForAllow

        public java.util.Set<HttpMethod> optionsForAllow(java.lang.String url,
                                                         java.lang.Object... uriVariables)
                                                  throws RestClientException
        Description copied from interface: RestOperations
        Return the value of the Allow header for the given URI.

        URI Template variables are expanded using the given URI variables, if any.

        Specified by:
        optionsForAllow in interface RestOperations
        Parameters:
        url - the URL
        uriVariables - the variables to expand in the template
        Returns:
        the value of the allow header
        Throws:
        RestClientException
      • optionsForAllow

        public java.util.Set<HttpMethod> optionsForAllow(java.lang.String url,
                                                         java.util.Map<java.lang.String,?> uriVariables)
                                                  throws RestClientException
        Description copied from interface: RestOperations
        Return the value of the Allow header for the given URI.

        URI Template variables are expanded using the given map.

        Specified by:
        optionsForAllow in interface RestOperations
        Parameters:
        url - the URL
        uriVariables - the variables to expand in the template
        Returns:
        the value of the allow header
        Throws:
        RestClientException
      • exchange

        public <T> ResponseEntity<T> exchange(java.lang.String url,
                                              HttpMethod method,
                                              @Nullable
                                              HttpEntity<?> requestEntity,
                                              java.lang.Class<T> responseType,
                                              java.lang.Object... uriVariables)
                                       throws RestClientException
        Description copied from interface: RestOperations
        Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.

        URI Template variables are expanded using the given URI variables, if any.

        Specified by:
        exchange in interface RestOperations
        Parameters:
        url - the URL
        method - the HTTP method (GET, POST, etc)
        requestEntity - the entity (headers and/or body) to write to the request may be null)
        responseType - the type of the return value
        uriVariables - the variables to expand in the template
        Returns:
        the response as entity
        Throws:
        RestClientException
      • exchange

        public <T> ResponseEntity<T> exchange(java.lang.String url,
                                              HttpMethod method,
                                              @Nullable
                                              HttpEntity<?> requestEntity,
                                              java.lang.Class<T> responseType,
                                              java.util.Map<java.lang.String,?> uriVariables)
                                       throws RestClientException
        Description copied from interface: RestOperations
        Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.

        URI Template variables are expanded using the given URI variables, if any.

        Specified by:
        exchange in interface RestOperations
        Parameters:
        url - the URL
        method - the HTTP method (GET, POST, etc)
        requestEntity - the entity (headers and/or body) to write to the request (may be null)
        responseType - the type of the return value
        uriVariables - the variables to expand in the template
        Returns:
        the response as entity
        Throws:
        RestClientException
      • exchange

        public <T> ResponseEntity<T> exchange(java.net.URI url,
                                              HttpMethod method,
                                              @Nullable
                                              HttpEntity<?> requestEntity,
                                              java.lang.Class<T> responseType)
                                       throws RestClientException
        Description copied from interface: RestOperations
        Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.
        Specified by:
        exchange in interface RestOperations
        Parameters:
        url - the URL
        method - the HTTP method (GET, POST, etc)
        requestEntity - the entity (headers and/or body) to write to the request (may be null)
        responseType - the type of the return value
        Returns:
        the response as entity
        Throws:
        RestClientException
      • exchange

        public <T> ResponseEntity<T> exchange(java.lang.String url,
                                              HttpMethod method,
                                              @Nullable
                                              HttpEntity<?> requestEntity,
                                              ParameterizedTypeReference<T> responseType,
                                              java.lang.Object... uriVariables)
                                       throws RestClientException
        Description copied from interface: RestOperations
        Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity. The given ParameterizedTypeReference is used to pass generic type information:
         ParameterizedTypeReference<List<MyBean>> myBean =
             new ParameterizedTypeReference<List<MyBean>>() {};
        
         ResponseEntity<List<MyBean>> response =
             template.exchange("http://example.com",HttpMethod.GET, null, myBean);
         
        Specified by:
        exchange in interface RestOperations
        Parameters:
        url - the URL
        method - the HTTP method (GET, POST, etc)
        requestEntity - the entity (headers and/or body) to write to the request (may be null)
        responseType - the type of the return value
        uriVariables - the variables to expand in the template
        Returns:
        the response as entity
        Throws:
        RestClientException
      • exchange

        public <T> ResponseEntity<T> exchange(java.lang.String url,
                                              HttpMethod method,
                                              @Nullable
                                              HttpEntity<?> requestEntity,
                                              ParameterizedTypeReference<T> responseType,
                                              java.util.Map<java.lang.String,?> uriVariables)
                                       throws RestClientException
        Description copied from interface: RestOperations
        Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity. The given ParameterizedTypeReference is used to pass generic type information:
         ParameterizedTypeReference<List<MyBean>> myBean =
             new ParameterizedTypeReference<List<MyBean>>() {};
        
         ResponseEntity<List<MyBean>> response =
             template.exchange("http://example.com",HttpMethod.GET, null, myBean);
         
        Specified by:
        exchange in interface RestOperations
        Parameters:
        url - the URL
        method - the HTTP method (GET, POST, etc)
        requestEntity - the entity (headers and/or body) to write to the request (may be null)
        responseType - the type of the return value
        uriVariables - the variables to expand in the template
        Returns:
        the response as entity
        Throws:
        RestClientException
      • exchange

        public <T> ResponseEntity<T> exchange(java.net.URI url,
                                              HttpMethod method,
                                              @Nullable
                                              HttpEntity<?> requestEntity,
                                              ParameterizedTypeReference<T> responseType)
                                       throws RestClientException
        Description copied from interface: RestOperations
        Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity. The given ParameterizedTypeReference is used to pass generic type information:
         ParameterizedTypeReference<List<MyBean>> myBean =
             new ParameterizedTypeReference<List<MyBean>>() {};
        
         ResponseEntity<List<MyBean>> response =
             template.exchange("http://example.com",HttpMethod.GET, null, myBean);
         
        Specified by:
        exchange in interface RestOperations
        Parameters:
        url - the URL
        method - the HTTP method (GET, POST, etc)
        requestEntity - the entity (headers and/or body) to write to the request (may be null)
        responseType - the type of the return value
        Returns:
        the response as entity
        Throws:
        RestClientException
      • exchange

        public <T> ResponseEntity<T> exchange(RequestEntity<?> requestEntity,
                                              java.lang.Class<T> responseType)
                                       throws RestClientException
        Description copied from interface: RestOperations
        Execute the request specified in the given RequestEntity and return the response as ResponseEntity. Typically used in combination with the static builder methods on RequestEntity, for instance:
         MyRequest body = ...
         RequestEntity request = RequestEntity
             .post(new URI("http://example.com/foo"))
             .accept(MediaType.APPLICATION_JSON)
             .body(body);
         ResponseEntity<MyResponse> response = template.exchange(request, MyResponse.class);
         
        Specified by:
        exchange in interface RestOperations
        Parameters:
        requestEntity - the entity to write to the request
        responseType - the type of the return value
        Returns:
        the response as entity
        Throws:
        RestClientException
      • exchange

        public <T> ResponseEntity<T> exchange(RequestEntity<?> requestEntity,
                                              ParameterizedTypeReference<T> responseType)
                                       throws RestClientException
        Description copied from interface: RestOperations
        Execute the request specified in the given RequestEntity and return the response as ResponseEntity. The given ParameterizedTypeReference is used to pass generic type information:
         MyRequest body = ...
         RequestEntity request = RequestEntity
             .post(new URI("http://example.com/foo"))
             .accept(MediaType.APPLICATION_JSON)
             .body(body);
         ParameterizedTypeReference<List<MyResponse>> myBean =
             new ParameterizedTypeReference<List<MyResponse>>() {};
         ResponseEntity<List<MyResponse>> response = template.exchange(request, myBean);
         
        Specified by:
        exchange in interface RestOperations
        Parameters:
        requestEntity - the entity to write to the request
        responseType - the type of the return value
        Returns:
        the response as entity
        Throws:
        RestClientException
      • acceptHeaderRequestCallback

        public <T> RequestCallback acceptHeaderRequestCallback(java.lang.Class<T> responseType)
        Return a RequestCallback that sets the request Accept header based on the given response type, cross-checked against the configured message converters.
      • httpEntityCallback

        public <T> RequestCallback httpEntityCallback(@Nullable
                                                      java.lang.Object requestBody)
        Return a RequestCallback implementation that writes the given object to the request stream.
      • httpEntityCallback

        public <T> RequestCallback httpEntityCallback(@Nullable
                                                      java.lang.Object requestBody,
                                                      java.lang.reflect.Type responseType)
        Return a RequestCallback implementation that:
        1. Sets the request Accept header based on the given response type, cross-checked against the configured message converters.
        2. Writes the given object to the request stream.