A minimalist REST client for Java
String url = "http://petstore.swagger.io/v2/pet/findByStatus";
TinyRest tiny = new TinyRest();
RestResponse result = tiny.get(url).withParam("status", "available").doRequest();
TinyRest tiny = new TinyRest();
String someJson = "{ \"name\":\"Idefix\", \"category\":\"dog\" }";
RestResponse result = tiny.post("http://petstore.swagger.io/v2/pet").withBody(someJson).doRequest();
tiny.get(url)
.basicAuth("login".getBytes(), "password".getBytes())
.doRequest();
There are convenient methods on the TinyRest class for that
TinyRest tiny = new TinyRest()
// ask this tiny instance to always send that Content-Type header
.alwaysApplyHeader("Content-Type", "application/json")
// ask this tiny instance to always use these credentials
.alwaysApplyBasicAuth("login".getBytes(), "password".getBytes());
RestResponse aResult = tiny.get(aUrl).doRequest();
RestResponse anotherResult = tiny.delete(anotherUrl).doRequest();
Proxy support is provided by Java's networking properties (host, port, non proxy hosts...) learn more at https://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html
The tiny.withGZip()
is a convenient method to ask the remote server for gzip compression. It adds the accept-encoding header.
// this
tiny.withGZip();
// is shorter than this
tiny.alwaysApplyHeader("accept-encoding", "gzip");