Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

GroundWork FoxHttp Request

Nikola Stanković edited this page Jan 10, 2017 · 3 revisions

Request

Structure of a FoxHttpRequest

The FoxHttpRequest is the main element of every request. It stores all needed information of the request itself. You can imagine it as a tab in your browser. Beside FoxHttpRequest there's FoxHttpClient which stores all information needed across all requests. You can imagine it as your browser or context in which your request runs.

Standard request

How can I configure a request?

To configure a standard request in FoxHttp you can create a new instance of FoxHttpRequest and then access its methods to configure. To execute the request and to get a response you have to call the .execute() method. This will return a non type save FoxHttpResponse. If you want a type save response you have to define a generic on the request and response (example: FoxHttpRequest<User> foxHttpRequest = new FoxHttpRequest<>(); and FoxHttpResponse<User>).

FoxHttpRequest foxHttpRequest = new FoxHttpRequest();
foxHttpRequest.setUrl(new URL("http://httpbin.org/get"));
FoxHttpResponse response = foxHttpRequest.execute();
System.out.println(response.toString(true));

Request builder

How can I configure a request?

IF you want to use the request builder you need to create a new instance of it. On this instance you've now the possibility to use the method chaining pattern to set your configuration. To get your request object you have to call the .build() method. After the execution of the build()-method the process is the same as it is for the default request.

This example is type save

FoxHttpRequestBuilder<PostResponse> requestBuilder = new FoxHttpRequestBuilder<>("http://httpbin.org/post", RequestType.POST).setRequestBody(new RequestStringBody("Request-Body", ContentType.DEFAULT_TEXT));
FoxHttpRequest<PostResponse> foxHttpRequest = requestBuilder.build();