REST Context
-
A simple yet very powerful API to integrate with any 3rd party REST / HTTP services.
-
Context Variable: rest
Supported HTTP Methods
- GET
- POST
- PUT
- DELETE
- HEAD
- OPTIONS
- PATCH
Usage
For detailed examples please visit Unirest API
Get Example
rest.get("http://httpbin.org").asString();
Post Example
rest.post("http://httpbin.org/post")
.field("parameter", "value")
.field("firstname", "Gary")
.asJson();
Route Parameters
rest.get("http://httpbin.org/{fruit}")
.routeParam("fruit", "apple")
.asString();
Query Parameters
rest.get("http://httpbin.org")
.queryString("fruit", "apple")
.queryString("droid", "R2D2")
.asString();
Header Parameters
rest.get("http://httpbin.org")
.header("Accept", "application/json")
.header("x-custom-header", "hello")
.asString();
Basic Authentication
rest.get("http://httpbin.org")
.basicAuth("user", "password1!")
.asString();
Body Data
rest.post("http://httpbin.org")
.body("This is the entire body")
.asEmpty();
Basic Forms
rest.post("http://httpbin.org")
.field("fruit", "apple")
.field("droid", "R2D2")
.asEmpty();
File Uploads
InputStream stream = new ByteArrayInputStream("file content data".getBytes());
rest.post("http://httpbin.org")
.field("upload", stream, "MyFile.txt")
.asEmpty();
API Interface
//See http://kong.github.io/unirest-java/#route-parameters
GetRequest get(String url);
//HTTP PUT Request, See: http://kong.github.io/unirest-java
HttpRequestWithBody put(String url);
//HTTP DELETE Request, See: http://kong.github.io/unirest-java
HttpRequestWithBody delete(String url);
//Closes all connection(s) and release resources
void close();
//HTTP OPTIONS Request, See: http://kong.github.io/unirest-java
GetRequest options(String url);
//HTTP HEAD Request, See: http://kong.github.io/unirest-java
GetRequest head(String url);
//See http://kong.github.io/unirest-java/#configuration
Config config();
//HTTP PATCH Request, See: http://kong.github.io/unirest-java
HttpRequestWithBody patch(String url);
//HTTP POST Request, See: http://kong.github.io/unirest-java
HttpRequestWithBody post(String url);
APIs Inherited From
Updated about 3 years ago