Class Http.Request
-
- All Implemented Interfaces:
-
java.io.Closeable
,java.lang.AutoCloseable
public class Http.Request implements Closeable
Request Builder
-
-
Field Summary
Fields Modifier and Type Field Description public final HttpURLConnection
conn
-
Constructor Summary
Constructors Constructor Description Http.Request(Http.QueryBuilder builder)
Builds a GET request with the specified QueryBuilder Http.Request(String url)
Builds a GET request with the specified url Http.Request(String url, String method)
Builds a request with the specified url and method
-
Method Summary
Modifier and Type Method Description Http.Request
setHeader(String key, String value)
Add a header Http.Request
setRequestTimeout(int timeout)
Sets the request connection and read timeout Http.Request
setFollowRedirects(boolean follow)
Sets whether redirects should be followed Http.Response
execute()
Execute the request Http.Response
executeWithBody(@NonNull() String body)
Execute the request with the specified body. Http.Response
executeWithBody(Array<byte> bytes)
Execute the request with the specified raw bytes. Http.Response
executeWithJson(Object body)
Execute the request with the specified object as json. Http.Response
executeWithJson(Gson gson, Object body)
Execute the request with the specified object as json. Http.Response
executeWithUrlEncodedForm(Map<String, Object> params)
Execute the request with the specified object as url encoded form data. Http.Response
executeWithMultipartForm(@NonNull() Map<String, Object> params)
Execute the request with the specified object as multipart form-data. Http.Response
executeWithMultipartForm(@NonNull() Map<String, Object> params, boolean doChunkedUploading)
void
close()
Closes this request static Http.Request
newDiscordRequest(Http.QueryBuilder builder)
Performs a GET request to a Discord route static Http.Request
newDiscordRequest(String route)
Performs a GET request to a Discord route static Http.Request
newDiscordRequest(String route, String method)
Performs a request to a Discord route static Http.Request
newDiscordRNRequest(Http.QueryBuilder builder)
Performs a GET request to a Discord route using RN headers static Http.Request
newDiscordRNRequest(String route)
Performs a request to a Discord route using RN headers static Http.Request
newDiscordRNRequest(String route, String method)
Performs a request to a Discord route using RN headers -
-
Constructor Detail
-
Http.Request
Http.Request(Http.QueryBuilder builder)
Builds a GET request with the specified QueryBuilder- Parameters:
builder
- QueryBuilder
-
Http.Request
Http.Request(String url)
Builds a GET request with the specified url- Parameters:
url
- Url
-
Http.Request
Http.Request(String url, String method)
Builds a request with the specified url and method- Parameters:
url
- Urlmethod
- HTTP method
-
-
Method Detail
-
setHeader
Http.Request setHeader(String key, String value)
Add a header
- Parameters:
key
- the namevalue
- the value
-
setRequestTimeout
Http.Request setRequestTimeout(int timeout)
Sets the request connection and read timeout
- Parameters:
timeout
- the timeout, in milliseconds
-
setFollowRedirects
Http.Request setFollowRedirects(boolean follow)
Sets whether redirects should be followed
- Parameters:
follow
- Whether redirects should be followed
-
execute
Http.Response execute()
Execute the request
-
executeWithBody
@NonNull() Http.Response executeWithBody(@NonNull() String body)
Execute the request with the specified body. May not be used in GET requests.
- Parameters:
body
- The request body
-
executeWithBody
@NonNull() Http.Response executeWithBody(Array<byte> bytes)
Execute the request with the specified raw bytes. May not be used in GET requests.
- Parameters:
bytes
- The request body in raw bytes
-
executeWithJson
Http.Response executeWithJson(Object body)
Execute the request with the specified object as json. May not be used in GET requests.
- Parameters:
body
- The request body
-
executeWithJson
Http.Response executeWithJson(Gson gson, Object body)
Execute the request with the specified object as json. May not be used in GET requests.
- Parameters:
gson
- Gson instancebody
- The request body
-
executeWithUrlEncodedForm
Http.Response executeWithUrlEncodedForm(Map<String, Object> params)
Execute the request with the specified object as url encoded form data. May not be used in GET requests.
- Parameters:
params
- the form data
-
executeWithMultipartForm
@NonNull() Http.Response executeWithMultipartForm(@NonNull() Map<String, Object> params)
Execute the request with the specified object as multipart form-data. May not be used in GET requests.
Please note that this will set the Transfer-Encoding to chunked. Some servers may not support this. To upload un-chunked (will lead to running out of memory when uploading large files), call
executeWithMultipartForm(params, false)
- Parameters:
params
- Map of params.
-
executeWithMultipartForm
Http.Response executeWithMultipartForm(@NonNull() Map<String, Object> params, boolean doChunkedUploading)
- Parameters:
doChunkedUploading
- Whether to upload in chunks.
-
close
void close()
Closes this request
-
newDiscordRequest
static Http.Request newDiscordRequest(Http.QueryBuilder builder)
Performs a GET request to a Discord route
- Parameters:
builder
- QueryBuilder
-
newDiscordRequest
static Http.Request newDiscordRequest(String route)
Performs a GET request to a Discord route
- Parameters:
route
- A Discord route, such as `/users/@me`
-
newDiscordRequest
static Http.Request newDiscordRequest(String route, String method)
Performs a request to a Discord route
- Parameters:
route
- A Discord route, such as `/users/@me`method
- HTTP method
-
newDiscordRNRequest
static Http.Request newDiscordRNRequest(Http.QueryBuilder builder)
Performs a GET request to a Discord route using RN headers
- Parameters:
builder
- QueryBuilder
-
newDiscordRNRequest
static Http.Request newDiscordRNRequest(String route)
Performs a request to a Discord route using RN headers
- Parameters:
route
- A Discord route, such as `/users/@me`
-
newDiscordRNRequest
static Http.Request newDiscordRNRequest(String route, String method)
Performs a request to a Discord route using RN headers
- Parameters:
route
- A Discord route, such as `/users/@me`method
- HTTP method
-
-
-
-