Package kong.unirest.core
Class UnirestInstance
- java.lang.Object
-
- kong.unirest.core.UnirestInstance
-
public class UnirestInstance extends Object
A Instance of the unirest runtime, you can have many of these but it is the config and its clients where all the action happens. This class is suitable for mocking.
-
-
Constructor Summary
Constructors Constructor Description UnirestInstance(Config config)
Create a new UnirestInstance with a config
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Wraps shutdown and will automatically be called when UnirestInstance is used with try-with-resource.Config
config()
Access the default configuration for the primary Unirest instance.HttpRequestWithBody
delete(String url)
Start a DELETE HttpRequest which supports a body from the primary configGetRequest
get(String url)
Start a GET HttpRequest which does not support a body from the primary configGetRequest
head(String url)
Start a HEAD HttpRequest which does not support a body from the primary configJsonPatchRequest
jsonPatch(String url)
Start a PATCH HttpRequest which supports a JSON Patch builder.GetRequest
options(String url)
Start a OPTIONS HttpRequest which does not support a body from the primary configHttpRequestWithBody
patch(String url)
Start a PATCH HttpRequest which supports a body from the primary configHttpRequestWithBody
post(String url)
Start a POST HttpRequest which supports a body from the primary configHttpRequestWithBody
put(String url)
Start a PUT HttpRequest which supports a body from the primary configHttpRequestWithBody
request(String method, String url)
void
reset()
Close the asynchronous client and its event loop.void
reset(boolean clearOptions)
Close the asynchronous client and its event loop.WebSocketRequest
webSocket(String url)
-
-
-
Constructor Detail
-
UnirestInstance
public UnirestInstance(Config config)
Create a new UnirestInstance with a config- Parameters:
config
- the config for the instance
-
-
Method Detail
-
config
public Config config()
Access the default configuration for the primary Unirest instance.- Returns:
- the instance's config
-
reset
public void reset()
Close the asynchronous client and its event loop. Use this method to close all the threads and allow an application to exit. This will also clear any options returning Unirest to a default state
-
reset
public void reset(boolean clearOptions)
Close the asynchronous client and its event loop. Use this method to close all the threads and allow an application to exit.- Parameters:
clearOptions
- indicates if options should be cleared. Note that the HttpClient, AsyncClient and thread monitors will not be retained after shutDown.
-
get
public GetRequest get(String url)
Start a GET HttpRequest which does not support a body from the primary config- Parameters:
url
- the endpoint to access. Can include placeholders for path params using curly braces {}- Returns:
- A HttpRequest builder
-
head
public GetRequest head(String url)
Start a HEAD HttpRequest which does not support a body from the primary config- Parameters:
url
- the endpoint to access. Can include placeholders for path params using curly braces {}- Returns:
- A HttpRequest builder
-
options
public GetRequest options(String url)
Start a OPTIONS HttpRequest which does not support a body from the primary config- Parameters:
url
- the endpoint to access. Can include placeholders for path params using curly braces {}- Returns:
- A HttpRequest builder
-
post
public HttpRequestWithBody post(String url)
Start a POST HttpRequest which supports a body from the primary config- Parameters:
url
- the endpoint to access. Can include placeholders for path params using curly braces {}- Returns:
- A HttpRequest builder
-
delete
public HttpRequestWithBody delete(String url)
Start a DELETE HttpRequest which supports a body from the primary config- Parameters:
url
- the endpoint to access. Can include placeholders for path params using curly braces {}- Returns:
- A HttpRequest builder
-
patch
public HttpRequestWithBody patch(String url)
Start a PATCH HttpRequest which supports a body from the primary config- Parameters:
url
- the endpoint to access. Can include placeholders for path params using curly braces {}- Returns:
- A HttpRequest builder
-
put
public HttpRequestWithBody put(String url)
Start a PUT HttpRequest which supports a body from the primary config- Parameters:
url
- the endpoint to access. Can include placeholders for path params using curly braces {}- Returns:
- A HttpRequest builder
-
jsonPatch
public JsonPatchRequest jsonPatch(String url)
Start a PATCH HttpRequest which supports a JSON Patch builder. this supports RFC-6902 https://tools.ietf.org/html/rfc6902- Parameters:
url
- the endpoint to access. Can include placeholders for path params using curly braces {}- Returns:
- A HttpRequest builder
-
request
public HttpRequestWithBody request(String method, String url)
-
close
public void close()
Wraps shutdown and will automatically be called when UnirestInstance is used with try-with-resource. This will alleviate the need to manually call shutDown as it will be done automatically.
-
webSocket
public WebSocketRequest webSocket(String url)
-
-