Package discord4j.rest.request
Class DiscordWebRequest
- java.lang.Object
-
- discord4j.rest.request.DiscordWebRequest
-
public class DiscordWebRequest extends Object
Template encoding all the needed information to make an HTTP request to Discord.
-
-
Constructor Summary
Constructors Constructor Description DiscordWebRequest(Route route, Object... uriVars)Create a newDiscordWebRequesttemplate based on aRouteand its compiled URI.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DiscordWebRequestbasicAuth(String base64EncodedValue)Use the given value as basic authentication.DiscordWebRequestbearerAuth(String accessToken)Use the given token as authentication value using the Bearer prefix.DiscordWebRequestbody(Object body)Set the given synchronousObjectas the body for the request.DiscordWebRequestcopy()Create a new instance using the values from this one.DiscordWebResponseexchange(Router router)Exchange this request through the givenRouter.AuthorizationSchemegetAuthorizationScheme()StringgetAuthorizationValue()ObjectgetBody()Return the body of this request, if present.StringgetCompleteUri()Return the compiled URI of this request.StringgetDescription()Map<String,Set<String>>getHeaders()Return the request headers, if present.Multimap<String,Object>getQueryParams()Return the query parameters saved in this request, if present.RoutegetRoute()Return the API endpoint targeted by this request.DiscordWebRequestheader(String key, String value)Adds the given key and value to the headers of this request.DiscordWebRequestoptionalHeader(String key, String value)Adds the given key and value to the headers of this request if and only ifvalueis notnull.DiscordWebRequestquery(Multimap<String,Object> params)Add the given names and values as request query parameters.DiscordWebRequestquery(String key, Object value)Add the given name and value as a request query parameter.DiscordWebRequestquery(Map<String,Object> params)Adds the given names and values as request query parameters.StringtoString()DiscordWebRequestunauthenticated()Use no authorization mechanism with this request.
-
-
-
Constructor Detail
-
DiscordWebRequest
public DiscordWebRequest(Route route, Object... uriVars)
Create a newDiscordWebRequesttemplate based on aRouteand its compiled URI.- Parameters:
route- the API resource targeted by this requesturiVars- the values to expand each template parameter
-
-
Method Detail
-
copy
public DiscordWebRequest copy()
Create a new instance using the values from this one.- Returns:
- a new request
-
getRoute
public Route getRoute()
Return the API endpoint targeted by this request.- Returns:
- the
Routeof thisDiscordWebRequest
-
getCompleteUri
public String getCompleteUri()
Return the compiled URI of this request.- Returns:
- the compiled URI, containing the actual path variables
-
getBody
@Nullable public Object getBody()
Return the body of this request, if present.- Returns:
- the body of this request, or
nullif this request carries no HTTP body
-
getQueryParams
@Nullable public Multimap<String,Object> getQueryParams()
Return the query parameters saved in this request, if present.- Returns:
- a map representing query parameters, or
nullif none are defined
-
getHeaders
@Nullable public Map<String,Set<String>> getHeaders()
Return the request headers, if present.- Returns:
- a map representing HTTP headers, or
nullif none are defined
-
getAuthorizationScheme
@Nullable public AuthorizationScheme getAuthorizationScheme()
-
body
public DiscordWebRequest body(Object body)
Set the given synchronousObjectas the body for the request.- Parameters:
body- the object to set as request body- Returns:
- this request
-
query
public DiscordWebRequest query(String key, Object value)
Add the given name and value as a request query parameter.- Parameters:
key- the query parameter namevalue- the query parameter value- Returns:
- this request
-
query
public DiscordWebRequest query(Map<String,Object> params)
Adds the given names and values as request query parameters.- Parameters:
params- a map of query parameter names to values- Returns:
- this request
-
query
public DiscordWebRequest query(Multimap<String,Object> params)
Add the given names and values as request query parameters.- Parameters:
params- a map of query parameter names to values- Returns:
- this request
-
header
public DiscordWebRequest header(String key, String value)
Adds the given key and value to the headers of this request.- Parameters:
key- the header keyvalue- the header value- Returns:
- this request
-
optionalHeader
public DiscordWebRequest optionalHeader(String key, @Nullable String value)
Adds the given key and value to the headers of this request if and only ifvalueis notnull.- Parameters:
key- the header keyvalue- the header value- Returns:
- this request
-
bearerAuth
public DiscordWebRequest bearerAuth(String accessToken)
Use the given token as authentication value using the Bearer prefix.- Parameters:
accessToken- the bearer token to use- Returns:
- this request
-
basicAuth
public DiscordWebRequest basicAuth(String base64EncodedValue)
Use the given value as basic authentication.- Parameters:
base64EncodedValue- the base64 encoded value to use- Returns:
- this request
-
unauthenticated
public DiscordWebRequest unauthenticated()
Use no authorization mechanism with this request.- Returns:
- this request
-
exchange
public DiscordWebResponse exchange(Router router)
Exchange this request through the givenRouter.- Parameters:
router- a router that performs this request- Returns:
- the result of this request
-
getDescription
public String getDescription()
-
-