Package me.geso.mech2

Class Mech2WithBase

java.lang.Object
me.geso.mech2.Mech2WithBase

public class Mech2WithBase extends Object
Mech2 object with base URI.

This class is useful when

  • to write Restful HTTP API client.
  • testing with embedded jetty
Author:
tokuhirom
  • Constructor Details

    • Mech2WithBase

      public Mech2WithBase(Mech2 mech2, URI baseURI)
  • Method Details

    • getMech2

      public Mech2 getMech2()
      Get a mech2 instance.
      Returns:
      mech2 instance
    • getBaseURI

      public URI getBaseURI()
      Get base URI
      Returns:
      base URI object
    • get

      public Mech2Request get(String path) throws URISyntaxException
      Create new GET request.
      Parameters:
      path - request path
      Returns:
      Generated request object.
      Throws:
      URISyntaxException
    • getf

      public Mech2Request getf(String pathFormat, Object... args) throws URISyntaxException
      Create new GET request using String.format(String, Object...).

      It's same as

      mech.get(String.format("/member/%s", member.getId())
      . But readable.
      Parameters:
      pathFormat - path format
      args - parameters.
      Returns:
      request object
      Throws:
      URISyntaxException
    • disableRedirectHandling

      public Mech2WithBase disableRedirectHandling()
      Disable redirect handling.
      Returns:
      fluent
    • post

      public Mech2Request post(String path) throws URISyntaxException
      Create new POST request.
      Parameters:
      path - path
      Returns:
      request object
      Throws:
      URISyntaxException
    • postJSON

      public Mech2Request postJSON(String path, Object data) throws URISyntaxException, com.fasterxml.jackson.core.JsonProcessingException
      Create new POST request contains JSON.
      Parameters:
      path - path to request
      data - source of JSON. It'll serialize by jackson.
      Returns:
      request object
      Throws:
      URISyntaxException
      com.fasterxml.jackson.core.JsonProcessingException
    • postMultipart

      public Mech2RequestMultipart postMultipart(String path)
      Create multi-part POST request(Charset is UTF-8).
      Parameters:
      path - path to request
      Returns:
      request object
    • postMultipart

      public Mech2RequestMultipart postMultipart(String path, Charset charset)
      Create new multi-part POST request.
      Parameters:
      path - path to request
      charset - charset
      Returns:
      request object