Skip to main content

ApiRequest

createRequest​

This is a builder method to build ApiRequest instance.

Important!

Always start composing the request with createRequest method.

final ApiRequest request = ApiRequest.createRequest ()
.method (GET)
.path ("/users/${userId}")
.pathParam ("userId", "2")
.create ();

contentType​

This method is used to set the content type of the request. Allowed values are:

  • FORM_URLENCODED
  • JSON (default)
  • MULTIPART_FORM_DATA
  • PLAIN_TEXT
final ApiRequest request = ApiRequest.createRequest ()
.contentType (ContentType.JSON)
.method (GET)
.path ("/users/${userId}")
.pathParam ("userId", "2")
.create ();

This method is used to set the header of the request.

final ApiRequest request = ApiRequest.createRequest ()
.contentType (ContentType.JSON)
.header ("Header-Key-1", "Header value 1")
.header ("Header-Key-2", "Header value 2")
.method (GET)
.path ("/users/${userId}")
.pathParam ("userId", "2")
.create ();

path​

This method is used to set the path of the request.

final ApiRequest request = ApiRequest.createRequest ()
.contentType (ContentType.JSON)
.header ("Header-Key-1", "Header value 1")
.header ("Header-Key-2", "Header value 2")
.method (GET)
.path ("/users/${userId}")
.pathParam ("userId", "2")
.create ();

pathParam​

This method is used to set the path parameter(s) of the request.

final ApiRequest request = ApiRequest.createRequest ()
.contentType (ContentType.JSON)
.header ("Header-Key-1", "Header value 1")
.header ("Header-Key-2", "Header value 2")
.method (GET)
.path ("/users/${userId}")
.pathParam ("userId", "2")
.create ();

queryParam​

This method is used to set the query parameter(s) of the request.

final ApiRequest request = ApiRequest.createRequest ()
.contentType (ContentType.JSON)
.header ("Header-Key-1", "Header value 1")
.header ("Header-Key-2", "Header value 2")
.method (GET)
.path ("/users/${userId}")
.pathParam ("userId", "2")
.queryParam ("param1", "value1")
.create ();

body​

This method is used to set the body of the request.

final ApiRequest request = ApiRequest.createRequest ()
.method (POST)
.path ("/users")
.body ("{\"name\":\"John\",\"job\":\"Developer\"}")
.create ();

bodyObject​

This method is used to set the body of the request using Java object.

final User user = User.createUser ()
.name ("Wasiq")
.job ("Software Engineer")
.create ();

final ApiRequest request = ApiRequest.createRequest ()
.method (POST)
.path ("/users")
.bodyObject (user)
.create ();

formBody​

This method is used to set the Form body of the request using key and value pairs.

final ApiRequest request = ApiRequest.createRequest ()
.method (POST)
.path ("/users")
.formBody ("strange", "boom")
.formBody ("test", "abc")
.create ();

method​

This method is used to set the method of the request. Following are the allowed values:

  • DELETE
  • GET
  • HEAD
  • OPTIONS
  • PATCH
  • POST
  • PUT
  • TRACE
final ApiRequest request = ApiRequest.createRequest ()
.method (RequestMethod.POST)
.path ("/users")
.bodyObject (user)
.create ();

userName​

This method is used to set the user name of the request.

final ApiRequest request = ApiRequest.createRequest ()
.method (POST)
.path ("/users")
.userName ("wasiq")
.password ("123456")
.bodyObject (user)
.create ();

password​

This method is used to set the password of the request.

final ApiRequest request = ApiRequest.createRequest ()
.method (POST)
.path ("/users")
.userName ("wasiq")
.password ("123456")
.bodyObject (user)
.create ();

create​

This method will create ApiRequest instance.

Important!

Always end composing the request with create method.

final ApiRequest request = ApiRequest.createRequest ()
.method (GET)
.path ("/users/${userId}")
.pathParam ("userId", "2")
.create ();