Class BackendRequest
java.lang.Object
net.streamlinecloud.mc.common.utils.BackendRequest
BackendRequest is a utility class for making HTTP requests to the backend.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
static enum
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfetch()
Fetches data from the backend server using the specified method and URL.void
fetch
(Consumer<BackendRequest> consumer) Fetches data from the backend server using the specified method and URL.setApplicationType
(BackendRequest.ApplicationType applicationType) Sets the request method.setAuth
(boolean auth) Sets whether to use authentication.
If set to true, the request will include an authorization header with a token.
If set to false, the request will not include an authorization header.
This should be set to false for public endpoints.
For most use cases it's not required to change auth to falsesetType
(@NonNull BackendRequest.RestType type) Sets the request method.Sets the request URL.Sets the request body.withHeaders
(Map<String, String> headers) Sets the request headers.
-
Constructor Details
-
BackendRequest
public BackendRequest()
-
-
Method Details
-
fetch
Fetches data from the backend server using the specified method and URL. This method is a shorthand for callingfetch(Consumer)
with an empty consumer. This method is useful for simple requests where no further processing is needed, the response is not needed or to store the response data and use it in another method or class. -
withBody
Sets the request body.- Parameters:
body
- the request body- Returns:
- this instance.
-
withHeaders
Sets the request headers.- Parameters:
headers
- the request headers- Returns:
- this instance.
-
setType
Sets the request method.- Parameters:
type
- the request method- Returns:
- this instance.
- See Also:
-
setAuth
Sets whether to use authentication.
If set to true, the request will include an authorization header with a token.
If set to false, the request will not include an authorization header.
This should be set to false for public endpoints.
For most use cases it's not required to change auth to false- Parameters:
auth
- true to use authentication, false to not use authentication - default is true- Returns:
- this instance.
-
setUrl
Sets the request URL.- Parameters:
url
- the request URL- Returns:
- this instance.
-
setApplicationType
Sets the request method.- Parameters:
applicationType
- the request application type- Returns:
- this instance.
- See Also:
-
fetch
Fetches data from the backend server using the specified method and URL.- Parameters:
consumer
- a consumer that accepts the BackendRequest instance as an argument
-