org.springframework.web.client
Interface RestOperations

All Known Implementing Classes:
RestTemplate

public interface RestOperations

Interface specifying a basic set of RESTful operations. Implemented by RestTemplate. Not often used directly, but a useful option to enhance testability, as it can easily be mocked or stubbed.

Since:
3.0
Author:
Arjen Poutsma
See Also:
RestTemplate

Method Summary
 void delete(String url, Map<String,String> uriVariables)
          Delete the resources at the specified URI.
 void delete(String url, String... uriVariables)
          Delete the resources at the specified URI.
<T> T
execute(String url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor, Map<String,String> uriVariables)
          Execute the HTTP methods to the given URI, preparing the request with the RequestCallback, and reading the response with a ResponseExtractor.
<T> T
execute(String url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor, String... uriVariables)
          Execute the HTTP methods to the given URI, preparing the request with the RequestCallback, and reading the response with a ResponseExtractor.
<T> T
getForObject(String url, Class<T> responseType, Map<String,String> uriVariables)
          Retrieve a representation by doing a GET on the URI template.
<T> T
getForObject(String url, Class<T> responseType, String... uriVariables)
          Retrieve a representation by doing a GET on the specified URL.
 HttpHeaders headForHeaders(String url, Map<String,String> uriVariables)
          Retrieve all headers of the resource specified by the URI template.
 HttpHeaders headForHeaders(String url, String... uriVariables)
          Retrieve all headers of the resource specified by the URI template.
 Set<HttpMethod> optionsForAllow(String url, Map<String,String> uriVariables)
          Return the value of the Allow header for the given URI.
 Set<HttpMethod> optionsForAllow(String url, String... uriVariables)
          Return the value of the Allow header for the given URI.
 URI postForLocation(String url, Object request, Map<String,String> uriVariables)
          Create a new resource by POSTing the given object to the URI template, and returns the value of the Location header.
 URI postForLocation(String url, Object request, String... uriVariables)
          Create a new resource by POSTing the given object to the URI template, and returns the value of the Location header.
<T> T
postForObject(String url, Object request, Class<T> responseType, Map<String,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(String url, Object request, Class<T> responseType, String... uriVariables)
          Create a new resource by POSTing the given object to the URI template, and returns the representation found in the response.
 void put(String url, Object request, Map<String,String> uriVariables)
          Creates a new resource by PUTting the given object to URI template.
 void put(String url, Object request, String... uriVariables)
          Create or update a resource by PUTting the given object to the URI.
 

Method Detail

getForObject

<T> T getForObject(String url,
                   Class<T> responseType,
                   String... uriVariables)
               throws RestClientException
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.

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

<T> T getForObject(String url,
                   Class<T> responseType,
                   Map<String,String> uriVariables)
               throws RestClientException
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.

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

HttpHeaders headForHeaders(String url,
                           String... uriVariables)
                           throws RestClientException
Retrieve all headers of the resource specified by the URI template.

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

Parameters:
url - the URL
uriVariables - the variables to expand the template
Returns:
all HTTP headers of that resource
Throws:
RestClientException

headForHeaders

HttpHeaders headForHeaders(String url,
                           Map<String,String> uriVariables)
                           throws RestClientException
Retrieve all headers of the resource specified by the URI template.

URI Template variables are expanded using the given map.

Parameters:
url - the URL
uriVariables - the map containing variables for the URI template
Returns:
all HTTP headers of that resource
Throws:
RestClientException

postForLocation

URI postForLocation(String url,
                    Object request,
                    String... uriVariables)
                    throws RestClientException
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.

Parameters:
url - the URL
request - the Object to be POSTed, may be null
Returns:
the value for the Location header
Throws:
RestClientException

postForLocation

URI postForLocation(String url,
                    Object request,
                    Map<String,String> uriVariables)
                    throws RestClientException
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.

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

postForObject

<T> T postForObject(String url,
                    Object request,
                    Class<T> responseType,
                    String... uriVariables)
                throws RestClientException
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.

Parameters:
url - the URL
request - the Object to be POSTed, may be null
Returns:
the converted object
Throws:
RestClientException

postForObject

<T> T postForObject(String url,
                    Object request,
                    Class<T> responseType,
                    Map<String,String> uriVariables)
                throws RestClientException
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.

Parameters:
url - the URL
request - the Object to be POSTed, may be null
Returns:
the converted object
Throws:
RestClientException

put

void put(String url,
         Object request,
         String... uriVariables)
         throws RestClientException
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.

Parameters:
url - the URL
request - the Object to be PUT, may be null
uriVariables - the variables to expand the template
Throws:
RestClientException

put

void put(String url,
         Object request,
         Map<String,String> uriVariables)
         throws RestClientException
Creates a new resource by PUTting the given object to URI template.

URI Template variables are expanded using the given map.

Parameters:
url - the URL
request - the Object to be PUT, may be null
uriVariables - the variables to expand the template
Throws:
RestClientException

delete

void delete(String url,
            String... uriVariables)
            throws RestClientException
Delete the resources at the specified URI.

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

Parameters:
url - the URL
uriVariables - the variables to expand in the template
Throws:
RestClientException

delete

void delete(String url,
            Map<String,String> uriVariables)
            throws RestClientException
Delete the resources at the specified URI.

URI Template variables are expanded using the given map.

Parameters:
url - the URL
uriVariables - the variables to expand the template
Throws:
RestClientException

optionsForAllow

Set<HttpMethod> optionsForAllow(String url,
                                String... uriVariables)
                                throws RestClientException
Return the value of the Allow header for the given URI.

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

Parameters:
url - the URL
uriVariables - the variables to expand in the template
Returns:
the value of the allow header
Throws:
RestClientException

optionsForAllow

Set<HttpMethod> optionsForAllow(String url,
                                Map<String,String> uriVariables)
                                throws RestClientException
Return the value of the Allow header for the given URI.

URI Template variables are expanded using the given map.

Parameters:
url - the URL
uriVariables - the variables to expand in the template
Returns:
the value of the allow header
Throws:
RestClientException

execute

<T> T execute(String url,
              HttpMethod method,
              RequestCallback requestCallback,
              ResponseExtractor<T> responseExtractor,
              String... uriVariables)
          throws RestClientException
Execute the HTTP methods to the given URI, preparing the request with the RequestCallback, and reading the response with a ResponseExtractor.

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

Parameters:
url - the URL
method - the HTTP method (GET, POST, etc)
requestCallback - object that prepares the request
responseExtractor - object that extracts the return value from the response
uriVariables - the variables to expand in the template
Returns:
an arbitrary object, as returned by the ResponseExtractor
Throws:
RestClientException

execute

<T> T execute(String url,
              HttpMethod method,
              RequestCallback requestCallback,
              ResponseExtractor<T> responseExtractor,
              Map<String,String> uriVariables)
          throws RestClientException
Execute the HTTP methods to the given URI, preparing the request with the RequestCallback, and reading the response with a ResponseExtractor.

URI Template variables are expanded using the given URI variables map.

Parameters:
url - the URL
method - the HTTP method (GET, POST, etc)
requestCallback - object that prepares the request
responseExtractor - object that extracts the return value from the response
uriVariables - the variables to expand in the template
Returns:
an arbitrary object, as returned by the ResponseExtractor
Throws:
RestClientException