APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.net

public Class HttpRequestBuilder

extends Object
Class Inheritance
Imports
java.io.InputStream, java.util.Map, com.badlogic.gdx.Net.HttpRequest, com.badlogic.gdx.utils.Base64Coder, .Json

A builder for HttpRequests. Make sure to call newRequest() first, then set the request up and obtain it via build() when you are done. It also offers a few utility methods to deal with content encoding and HTTP headers.
Author
Daniel Holderbaum

Field Summary

Modifier and TypeField and Description
public static String
baseUrl

Will be added as a prefix to each URL when url(String) is called.

public static int
defaultTimeout

Will be set for each new HttpRequest.

private Net.HttpRequest
public static Json
json

Will be used for the object serialization in case jsonContent(Object) is called.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public HttpRequestBuilder
basicAuthentication(String username, String password)

Sets the Authorization header via the Base64 encoded username and password.

public Net.HttpRequest
build()

Returns the HttpRequest that has been setup by this builder so far.

public HttpRequestBuilder
content(String content)

public HttpRequestBuilder
content(InputStream contentStream, long contentLength)

public HttpRequestBuilder
followRedirects(boolean followRedirects)

public HttpRequestBuilder
formEncodedContent(Map<String, String> content)

Sets the correct ContentType and encodes the given parameter map, then sets it as the content.

public HttpRequestBuilder
header(String name, String value)

public HttpRequestBuilder
includeCredentials(boolean includeCredentials)

public HttpRequestBuilder
jsonContent(Object content)

Sets the correct ContentType and encodes the given content object via json, then sets it as the content.

public HttpRequestBuilder
method(String httpMethod)

public HttpRequestBuilder
newRequest()

Initializes the builder and sets it up to build a new HttpRequest .

public HttpRequestBuilder
timeout(int timeOut)

If this method is not called, the defaultTimeout will be used.

public HttpRequestBuilder
url(String url)

The baseUrl will automatically be added as a prefix to the given URL.

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

baseUrlback to summary
public static String baseUrl

Will be added as a prefix to each URL when url(String) is called. Empty by default.

defaultTimeoutback to summary
public static int defaultTimeout

Will be set for each new HttpRequest. By default set to 1000. Can be overwritten via timeout(int).

httpRequestback to summary
private Net.HttpRequest httpRequest
jsonback to summary
public static Json json

Will be used for the object serialization in case jsonContent(Object) is called.

Constructor Detail

HttpRequestBuilderback to summary
public HttpRequestBuilder()

Method Detail

basicAuthenticationback to summary
public HttpRequestBuilder basicAuthentication(String username, String password)

Sets the Authorization header via the Base64 encoded username and password.

buildback to summary
public Net.HttpRequest build()

Returns the HttpRequest that has been setup by this builder so far. After using the request, it should be returned to the pool via Pools.free(request).

contentback to summary
public HttpRequestBuilder content(String content)
See Also
HttpRequest#setContent(String)
contentback to summary
public HttpRequestBuilder content(InputStream contentStream, long contentLength)
See Also
HttpRequest#setContent(java.io.InputStream, long)
followRedirectsback to summary
public HttpRequestBuilder followRedirects(boolean followRedirects)
See Also
HttpRequest#setFollowRedirects(boolean)
formEncodedContentback to summary
public HttpRequestBuilder formEncodedContent(Map<String, String> content)

Sets the correct ContentType and encodes the given parameter map, then sets it as the content.

headerback to summary
public HttpRequestBuilder header(String name, String value)
See Also
HttpRequest#setHeader(String, String)
includeCredentialsback to summary
public HttpRequestBuilder includeCredentials(boolean includeCredentials)
See Also
HttpRequest#setIncludeCredentials(boolean)
jsonContentback to summary
public HttpRequestBuilder jsonContent(Object content)

Sets the correct ContentType and encodes the given content object via json, then sets it as the content.

methodback to summary
public HttpRequestBuilder method(String httpMethod)
See Also
HttpRequest#setMethod(String)
newRequestback to summary
public HttpRequestBuilder newRequest()

Initializes the builder and sets it up to build a new HttpRequest .

timeoutback to summary
public HttpRequestBuilder timeout(int timeOut)

If this method is not called, the defaultTimeout will be used.

See Also
HttpRequest#setTimeOut(int)
urlback to summary
public HttpRequestBuilder url(String url)

The baseUrl will automatically be added as a prefix to the given URL.

See Also
HttpRequest#setUrl(String)
validateback to summary
private void validate()