Class UnirestInstance


  • public class UnirestInstance
    extends java.lang.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.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Config config  
    • 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​(java.lang.String url)
      Start a DELETE HttpRequest which supports a body from the primary config
      GetRequest get​(java.lang.String url)
      Start a GET HttpRequest which does not support a body from the primary config
      GetRequest head​(java.lang.String url)
      Start a HEAD HttpRequest which does not support a body from the primary config
      JsonPatchRequest jsonPatch​(java.lang.String url)
      Start a PATCH HttpRequest which supports a JSON Patch builder.
      GetRequest options​(java.lang.String url)
      Start a OPTIONS HttpRequest which does not support a body from the primary config
      HttpRequestWithBody patch​(java.lang.String url)
      Start a PATCH HttpRequest which supports a body from the primary config
      HttpRequestWithBody post​(java.lang.String url)
      Start a POST HttpRequest which supports a body from the primary config
      HttpRequestWithBody put​(java.lang.String url)
      Start a PUT HttpRequest which supports a body from the primary config
      HttpRequestWithBody request​(java.lang.String method, java.lang.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​(java.lang.String url)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • config

        private final Config config
    • 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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.String method,
                                           java.lang.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.