Class RestMethods
- java.lang.Object
-
- io.toro.martini.RestMethods
-
public final class RestMethods extends Object
Provides one-liners for easily executing HTTP requests in Groovy.
-
-
Constructor Summary
Constructors Constructor Description RestMethods(io.toro.martini.service.UrlRewriter urlRewriter)
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ObjectjsonDelete(String url)Execute a DELETE request against a web service.static ObjectjsonDelete(String url, Map<String,?> params)Execute a DELETE request against a web service.static ObjectjsonGet(String url)Execute a GET request against a web service.static ObjectjsonGet(String url, Closure closure)Execute a GET request against a web service.static ObjectjsonGet(String url, Map<String,?> params)Execute a GET request against a web service.static ObjectjsonGet(String url, Map<String,?> params, Closure closure)Execute a GET request against a web service.static ObjectjsonHead(String url)Execute a HEAD request against a web service.static ObjectjsonHead(String url, Map<String,?> params)Execute a HEAD request against a web service.static ObjectjsonOptions(String url)Execute an OPTIONS request against a web service.static ObjectjsonOptions(String url, Map<String,?> params)Execute an OPTIONS request against a web service.static ObjectjsonPatch(String url)Execute a PATCH request against a web service.static ObjectjsonPatch(String url, Map<String,?> params)Execute a PATCH request against a web service.static ObjectjsonPost(String url)Execute a POST request against a web service.static ObjectjsonPost(String url, Closure closure)Execute a POST request against a web service.static ObjectjsonPost(String url, Map<String,?> params)Execute a POST request against a web service.static ObjectjsonPost(String url, Map<String,?> params, Closure closure)Execute a POST request against a web service.static ObjectjsonPut(String url)Execute a POST request against a web service.static ObjectjsonPut(String url, Map<String,?> params)Execute a POST request against a web service.static Objectrequest(String url, String method, groovyx.net.http.ContentType contentType, Closure configClosure)Send a request, configured after the provided request data, to a RESTful web service.static Objectrequest(String url, String method, groovyx.net.http.ContentType contentType, Map<String,?> params, Closure responseClosure)Send a request, configured after the provided request data, to a RESTful web service.static ObjectxmlDelete(String url)Execute a DELETE request against a web service.static ObjectxmlDelete(String url, Map<String,?> params)Execute a DELETE request against a web service.static ObjectxmlGet(String url)Execute a GET request against a web service.static ObjectxmlGet(String url, Closure closure)Execute a GET request against a web service.static ObjectxmlGet(String url, Map<String,?> params)Execute a GET request against a web service.static ObjectxmlGet(String url, Map<String,?> params, Closure closure)Execute a GET request against a web service.static ObjectxmlHead(String url)Execute a HEAD request against a web service.static ObjectxmlHead(String url, Map<String,?> params)Execute a HEAD request against a web service.static ObjectxmlOptions(String url)Execute an OPTIONS request against a web service.static ObjectxmlOptions(String url, Map<String,?> params)Execute an OPTIONS request against a web service.static ObjectxmlPatch(String url)Execute a PATCH request against a web service.static ObjectxmlPatch(String url, Map<String,?> params)Execute a PATCH request against a web service.static ObjectxmlPost(String url)Execute a POST request against a web service.static ObjectxmlPost(String url, Closure closure)Execute a POST request against a web service.static ObjectxmlPost(String url, Map<String,?> params)Execute a POST request against a web service.static ObjectxmlPost(String url, Map<String,?> params, Closure closure)Execute a POST request against a web service.static ObjectxmlPut(String url)Execute a PUT request against a web service.static ObjectxmlPut(String url, Map<String,?> params)Execute a PUT request against a web service.
-
-
-
Constructor Detail
-
RestMethods
@Autowired RestMethods(io.toro.martini.service.UrlRewriter urlRewriter)
-
-
Method Detail
-
request
public static Object request(String url, String method, groovyx.net.http.ContentType contentType, Map<String,?> params, Closure responseClosure) throws IOException, URISyntaxException
Send a request, configured after the provided request data, to a RESTful web service.- Parameters:
uri- the URL of the RESTful web servicemethod- the type of HTTP method to usecontentType- the content type of the request and responseparams-a map of parametersresponseClosure- closure to execute after the response has been received- Returns:
- the response, as generated by the response handler
- Throws:
IllegalArgumentException- if provided HTTP method is unknownIOExceptionURISyntaxException- Since:
- 1.0
-
request
public static Object request(String url, String method, groovyx.net.http.ContentType contentType, Closure configClosure) throws IOException, URISyntaxException
Send a request, configured after the provided request data, to a RESTful web service. This one-liner allows the caller to further configure request properties underconfigClosurethroughRequestConfigDelegate. Configurable properties include, but are not limited to:- the URI path
- query parameters
- request body
- response handlers
- Parameters:
url- the URL of the RESTful web servicemethod- the URL of the RESTful web servicecontentType- the content type of the request and response; either aContentTypeor valid content-type stringconfigClosure- closure from which to configure request options- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
jsonDelete
public static Object jsonDelete(String url) throws IOException, URISyntaxException
Execute a DELETE request against a web service. JSON will be used as the request and response content type.
Example usage:
def data = 'http://my.host/api/resource'.jsonDelete().data
- Parameters:
url- the URL of the RESTful web service- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
jsonDelete
public static Object jsonDelete(String url, Map<String,?> params) throws IOException, URISyntaxException
Execute a DELETE request against a web service. JSON will be used as the request and response content type. Parameters for the to-be-executed request can be provided through
params.Example usage:
def data = 'http://my.host/api/resource'.jsonDelete( [ 'queryString': 'page=1&size=50' ] ).data
- Parameters:
url- the URL of the RESTful web serviceparams-a map of parameters- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
jsonGet
public static Object jsonGet(String url, Map<String,?> params, Closure closure) throws IOException, URISyntaxException
Execute a GET request against a web service. JSON will be used as the request and response content type. Parameters for the to-be-executed request can be provided through
params. Additional processing for the response can be done throughclosure.Example usage:
def data = 'http://my.host/api/resource'.jsonGet( [ 'queryString': 'page=1&size=50' ] ) { response, reader -> { return reader } }- Parameters:
url- the URL of the RESTful web serviceparams-a map of parametersclosure- closure to call after receiving the response, for further processing- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
jsonGet
public static Object jsonGet(String url, Closure closure) throws IOException, URISyntaxException
Execute a GET request against a web service. JSON will be used as the request and response content type. Additional processing for the response can be done through
closure.Example usage:
def data = 'http://my.host/api/resource'.jsonGet() { response, reader -> { return reader } }- Parameters:
url- the URL of the RESTful web serviceclosure- closure to call after receiving the response, for further processing- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
jsonGet
public static Object jsonGet(String url, Map<String,?> params) throws IOException, URISyntaxException
Execute a GET request against a web service. JSON will be used as the request and response content type. Parameters for the to-be-executed request can be provided through
params.Example usage:
def data = 'http://my.host/api/resource'.jsonGet( [ 'queryString': 'page=1&size=50' ] ).data
- Parameters:
url- the URL of the RESTful web serviceparams-a map of parameters- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
jsonGet
public static Object jsonGet(String url) throws IOException, URISyntaxException
Execute a GET request against a web service. JSON will be used as the request and response content type.
Example usage:
def data = 'http://my.host/api/resource'.jsonGet().data
- Parameters:
url- the URL of the RESTful web service- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
jsonHead
public static Object jsonHead(String url, Map<String,?> params) throws IOException, URISyntaxException
Execute a HEAD request against a web service. JSON will be used as the request and response content type. Parameters for the to-be-executed request can be provided through
params.Example usage:
def data = 'http://my.host/api/resource'.jsonHead( [ 'queryString': 'page=1&size=50' ] ).data
- Parameters:
url- the URL of the RESTful web serviceparams-a map of parameters- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
jsonHead
public static Object jsonHead(String url) throws IOException, URISyntaxException
Execute a HEAD request against a web service. JSON will be used as the request and response content type.
Example usage:
def data = 'http://my.host/api/resource'.jsonHead().data
- Parameters:
url- the URL of the RESTful web service- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
jsonOptions
public static Object jsonOptions(String url, Map<String,?> params) throws IOException, URISyntaxException
Execute an OPTIONS request against a web service. JSON will be used as the request and response content type. Parameters for the to-be-executed request can be provided through
params.Example usage:
def data = 'http://my.host/api/resource'.jsonOptions( [ 'queryString': 'page=1&size=50' ] ).data
- Parameters:
url- the URL of the RESTful web serviceparams-a map of parameters- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
jsonOptions
public static Object jsonOptions(String url) throws IOException, URISyntaxException
Execute an OPTIONS request against a web service. JSON will be used as the request and response content type.
Example usage:
def data = 'http://my.host/api/resource'.jsonOptions().data
- Parameters:
url- the URL of the RESTful web service- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
jsonPatch
public static Object jsonPatch(String url, Map<String,?> params) throws IOException, URISyntaxException
Execute a PATCH request against a web service. JSON will be used as the request and response content type. Parameters for the to-be-executed request can be provided through
params.Example usage:
def data = 'http://my.host/api/resource'.jsonPatch( [ 'queryString': 'page=1&size=50' ] ).data
- Parameters:
url- the URL of the RESTful web serviceparams-a map of parameters- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
jsonPatch
public static Object jsonPatch(String url) throws IOException, URISyntaxException
Execute a PATCH request against a web service. JSON will be used as the request and response content type.
Example usage:
def data = 'http://my.host/api/resource'.jsonPatch().data
- Parameters:
url- the URL of the RESTful web service- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
jsonPost
public static Object jsonPost(String url, Map<String,?> params, Closure closure) throws IOException, URISyntaxException
Execute a POST request against a web service. JSON will be used as the request and response content type. Parameters for the to-be-executed request can be provided through
params. Additional processing for the response can be done throughclosure.Example usage:
def data = 'http://my.host/api/resource'.jsonPost( [ 'queryString': 'page=1&size=50' ] ) { response, reader -> { return reader } }- Parameters:
url- the URL of the RESTful web serviceparams-a map of parametersclosure- closure to call after receiving the response, for further processing- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
jsonPost
public static Object jsonPost(String url, Closure closure) throws IOException, URISyntaxException
Execute a POST request against a web service. JSON will be used as the request and response content type. Additional processing for the response can be done through
closure.Example usage:
def data = 'http://my.host/api/resource'.jsonPost() { response, reader -> { return reader } }- Parameters:
url- the URL of the RESTful web serviceclosure- closure to call after receiving the response, for further processing- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
jsonPost
public static Object jsonPost(String url, Map<String,?> params) throws IOException, URISyntaxException
Execute a POST request against a web service. JSON will be used as the request and response content type. Parameters for the to-be-executed request can be provided through
params.Example usage:
def data = 'http://my.host/api/resource'.jsonPost( [ 'queryString': 'page=1&size=50' ] ).data
- Parameters:
url- the URL of the RESTful web serviceparams-a map of parameters- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
jsonPost
public static Object jsonPost(String url) throws IOException, URISyntaxException
Execute a POST request against a web service. JSON will be used as the request and response content type.
Example usage:
def data = 'http://my.host/api/resource'.jsonPost().data
- Parameters:
url- the URL of the RESTful web service- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
jsonPut
public static Object jsonPut(String url, Map<String,?> params) throws IOException, URISyntaxException
Execute a POST request against a web service. JSON will be used as the request and response content type. Parameters for the to-be-executed request can be provided through
params.Example usage:
def data = 'http://my.host/api/resource'.jsonPut( [ 'queryString': 'page=1&size=50' ] ).data
- Parameters:
url- the URL of the RESTful web serviceparams-a map of parameters- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
jsonPut
public static Object jsonPut(String url) throws IOException, URISyntaxException
Execute a POST request against a web service. JSON will be used as the request and response content type.
Example usage:
def data = 'http://my.host/api/resource'.jsonPut().data
- Parameters:
url- the URL of the RESTful web service- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
xmlDelete
public static Object xmlDelete(String url, Map<String,?> params) throws IOException, URISyntaxException
Execute a DELETE request against a web service. XML will be used as the request and response content type. Parameters for the to-be-executed request can be provided through
params.Example usage:
def data = 'http://my.host/api/resource'.xmlDelete( [ 'queryString': 'page=1&size=50' ] ).data
- Parameters:
url- the URL of the RESTful web serviceparams-a map of parameters- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
xmlDelete
public static Object xmlDelete(String url) throws IOException, URISyntaxException
Execute a DELETE request against a web service. XML will be used as the request and response content type.
Example usage:
def data = 'http://my.host/api/resource'.xmlDelete().data
- Parameters:
url- the URL of the RESTful web service- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
xmlGet
public static Object xmlGet(String url, Map<String,?> params, Closure closure) throws IOException, URISyntaxException
Execute a GET request against a web service. XML will be used as the request and response content type. Parameters for the to-be-executed request can be provided through
params. Additional processing for the response can be done throughclosure.Example usage:
def data = 'http://my.host/api/resource'.xmlGet( [ 'queryString': 'page=1&size=50' ] ) { response, reader -> { return reader } }- Parameters:
url- the URL of the RESTful web serviceparams-a map of parametersclosure- closure to call after receiving the response, for further processing- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
xmlGet
public static Object xmlGet(String url, Closure closure) throws IOException, URISyntaxException
Execute a GET request against a web service. XML will be used as the request and response content type. Additional processing for the response can be done through
closure.Example usage:
def data = 'http://my.host/api/resource'.xmlGet() { response, reader -> { return reader } }- Parameters:
url- the URL of the RESTful web serviceclosure- closure to call after receiving the response, for further processing- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
xmlGet
public static Object xmlGet(String url, Map<String,?> params) throws IOException, URISyntaxException
Execute a GET request against a web service. XML will be used as the request and response content type. Parameters for the to-be-executed request can be provided through
params.Example usage:
def data = 'http://my.host/api/resource'.xmlGet( [ 'queryString': 'page=1&size=50' ] ).data
- Parameters:
url- the URL of the RESTful web serviceparams-a map of parameters- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
xmlGet
public static Object xmlGet(String url) throws IOException, URISyntaxException
Execute a GET request against a web service. XML will be used as the request and response content type. Parameters for the to-be-executed request can be provided through
params.Example usage:
def data = 'http://my.host/api/resource'.xmlGet().data
- Parameters:
url- the URL of the RESTful web service- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
xmlHead
public static Object xmlHead(String url, Map<String,?> params) throws IOException, URISyntaxException
Execute a HEAD request against a web service. XML will be used as the request and response content type. Parameters for the to-be-executed request can be provided through
params.Example usage:
def data = 'http://my.host/api/resource'.xmlHead( [ 'queryString': 'page=1&size=50' ] ).data
- Parameters:
url- the URL of the RESTful web serviceparams-a map of parameters- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
xmlHead
public static Object xmlHead(String url) throws IOException, URISyntaxException
Execute a HEAD request against a web service. XML will be used as the request and response content type.
Example usage:
def data = 'http://my.host/api/resource'.xmlHead().data
- Parameters:
url- the URL of the RESTful web service- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
xmlOptions
public static Object xmlOptions(String url, Map<String,?> params) throws IOException, URISyntaxException
Execute an OPTIONS request against a web service. XML will be used as the request and response content type. Parameters for the to-be-executed request can be provided through
params.Example usage:
def data = 'http://my.host/api/resource'.xmlOptions( [ 'queryString': 'page=1&size=50' ] ).data
- Parameters:
url- the URL of the RESTful web serviceparams-a map of parameters- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
xmlOptions
public static Object xmlOptions(String url) throws IOException, URISyntaxException
Execute an OPTIONS request against a web service. XML will be used as the request and response content type.
Example usage:
def data = 'http://my.host/api/resource'.xmlOptions().data
- Parameters:
url- the URL of the RESTful web service- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
xmlPatch
public static Object xmlPatch(String url) throws IOException, URISyntaxException
Execute a PATCH request against a web service. XML will be used as the request and response content type.
Example usage:
def data = 'http://my.host/api/resource'.xmlPatch().data
- Parameters:
url- the URL of the RESTful web service- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
xmlPatch
public static Object xmlPatch(String url, Map<String,?> params) throws IOException, URISyntaxException
Execute a PATCH request against a web service. XML will be used as the request and response content type. Parameters for the to-be-executed request can be provided through
params.Example usage:
def data = 'http://my.host/api/resource'.xmlPatch( [ 'queryString': 'page=1&size=50' ] ).data
- Parameters:
url- the URL of the RESTful web serviceparams-a map of parameters- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
xmlPost
public static Object xmlPost(String url, Map<String,?> params, Closure closure) throws IOException, URISyntaxException
Execute a POST request against a web service. XML will be used as the request and response content type. Parameters for the to-be-executed request can be provided through
params. Additional processing for the response can be done throughclosure.Example usage:
def data = 'http://my.host/api/resource'.xmlPost( [ 'queryString': 'page=1&size=50' ] ) { response, reader -> { return reader } }- Parameters:
url- the URL of the RESTful web serviceparams-a map of parametersclosure- closure to call after receiving the response, for further processing- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
xmlPost
public static Object xmlPost(String url, Closure closure) throws IOException, URISyntaxException
Execute a POST request against a web service. XML will be used as the request and response content type. Additional processing for the response can be done through
closure.Example usage:
def data = 'http://my.host/api/resource'.xmlPost() { response, reader -> { return reader } }- Parameters:
url- the URL of the RESTful web serviceclosure- closure to call after receiving the response, for further processing- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
xmlPost
public static Object xmlPost(String url, Map<String,?> params) throws IOException, URISyntaxException
Execute a POST request against a web service. XML will be used as the request and response content type. Parameters for the to-be-executed request can be provided through
params.Example usage:
def data = 'http://my.host/api/resource'.xmlPost( [ 'queryString': 'page=1&size=50' ] ).data
- Parameters:
url- the URL of the RESTful web serviceparams-a map of parameters- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
xmlPost
public static Object xmlPost(String url) throws IOException, URISyntaxException
Execute a POST request against a web service. XML will be used as the request and response content type.
Example usage:
def data = 'http://my.host/api/resource'.xmlPost().data
- Parameters:
url- the URL of the RESTful web service- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
xmlPut
public static Object xmlPut(String url, Map<String,?> params) throws IOException, URISyntaxException
Execute a PUT request against a web service. XML will be used as the request and response content type. Parameters for the to-be-executed request can be provided through
params.Example usage:
def data = 'http://my.host/api/resource'.xmlPut( [ 'queryString': 'page=1&size=50' ] ).data
- Parameters:
url- the URL of the RESTful web serviceparams-a map of parameters- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
xmlPut
public static Object xmlPut(String url) throws IOException, URISyntaxException
Execute a PUT request against a web service. XML will be used as the request and response content type.
Example usage:
def data = 'http://my.host/api/resource'.xmlPut().data
- Parameters:
url- the URL of the RESTful web service- Returns:
- response returned by the server
- Throws:
IOExceptionURISyntaxException- Since:
- 1.0
-
-