APIRequest
The APIRequest
class is useful to send and manage any "API"
requests and their responses
Author
N7ghtm4r3 - Tecknobit
Since
1.0.0
Constructors
Link copied to clipboard
Constructor to init APIRequest
Constructor to init APIRequest
Constructor to init APIRequest
Constructor to init APIRequest
Constructor to init APIRequest
Constructor to init APIRequest
constructor(defaultErrorResponse: String, requestTimeout: Long, enableCertificatesValidation: Boolean)
Constructor to init APIRequest
constructor()
Constructor to init APIRequest No-any params required
Types
Properties
Link copied to clipboard
contentType
is the type of the content of the payload request, default is "text/plain"
Link copied to clipboard
DEFAULT_ERROR_RESPONSE
is constant that contains default error message if user not custom itLink copied to clipboard
DEFAULT_REQUEST_TIMEOUT
is constant that contains default request timeout if user not custom itLink copied to clipboard
defaultErrorResponse
is the instance that contains default error messageLink copied to clipboard
enableCertificatesValidation
whether enable the SSL certificates validation, this for example when the certificate is a self-signed certificate to by-passLink copied to clipboard
errorResponse
is the instance that contains error message from requestLink copied to clipboard
HMAC_SHA256_ALGORITHM
is constant that contains "HMAC SHA 256"
algorithm typeLink copied to clipboard
HMAC_SHA512_ALGORITHM
is constant that contains "HMAC SHA 512"
algorithm typeLink copied to clipboard
isSuccessfulRequest
whether the request has been successfulLink copied to clipboard
MD5_ALGORITHM
is constant that contains "MD5"
algorithm typeLink copied to clipboard
**okHttpClient** -> the http client to execute the requests
Link copied to clipboard
SHA1_ALGORITHM
is constant that contains "SHA-1"
algorithm typeLink copied to clipboard
SHA256_ALGORITHM
is constant that contains "SHA-256"
algorithm typeLink copied to clipboard
statusCode
status code of a requestFunctions
Link copied to clipboard
Method to concatenate a list of params
Link copied to clipboard
Method to get digest
Link copied to clipboard
Method to check if the pathname (without the name and the suffix of the file to save) given by the user exists then if not exists create that pathname
Link copied to clipboard
Method to create a data URI scheme
Link copied to clipboard
Method to download a file from an
"URL"
sourceLink copied to clipboard
Method to set programmatically enableCertificatesValidation value
Link copied to clipboard
open fun <T> encodeAdditionalParams(mandatoryParams: String, extraParams: APIRequest.Params): String
Method to assemble a query string params of an
"HTTP"
requestLink copied to clipboard
Method to assemble a body params of an
"HTTP"
requestLink copied to clipboard
Method to assemble a query params for an
"HTTP"
requestLink copied to clipboard
Link copied to clipboard
Method to get the error response of the request No-any params required
Link copied to clipboard
Method to get the response of the request No-any params required
Link copied to clipboard
Method to get status response code of the request No-any params required
Link copied to clipboard
Method to get params signature for an
"HTTP"
requestLink copied to clipboard
Method to get whether the response has been successful No-any params required
Link copied to clipboard
Method to parse the response of the request and format it as
"JSON"
Link copied to clipboard
Method to get the response of an
"HTTP"
request No-any params requiredLink copied to clipboard
Method to print the error response of the request No-any params required
Link copied to clipboard
Method to print the error response of the request No-any params required
Link copied to clipboard
open fun sendAPIRequest(requestUrl: String, method: APIRequest.RequestMethod, queryParams: APIRequest.Params)
Method to send an api request
open fun sendAPIRequest(requestUrl: String, method: APIRequest.RequestMethod, headers: APIRequest.Headers)
open fun sendAPIRequest(requestUrl: String, method: APIRequest.RequestMethod, headers: APIRequest.Headers, queryParams: APIRequest.Params)
Method to send an api request with different headers
open fun <T> sendAPIRequest(requestUrl: String, method: APIRequest.RequestMethod, headerKey: String, headerValue: T)
open fun <T> sendAPIRequest(requestUrl: String, method: APIRequest.RequestMethod, headerKey: String, headerValue: T, queryParams: APIRequest.Params)
Method to send an api request with a single header
Link copied to clipboard
open fun sendJSONPayloadedAPIRequest(requestUrl: String, method: APIRequest.RequestMethod, payload: APIRequest.Params)
Method to send an api request with a payload formatted in
"JSON"
open fun sendJSONPayloadedAPIRequest(requestUrl: String, method: APIRequest.RequestMethod, headers: APIRequest.Headers, payload: APIRequest.Params)
Method to send an api request with a payload formatted in
"JSON"
and with different headersopen fun <T> sendJSONPayloadedAPIRequest(requestUrl: String, method: APIRequest.RequestMethod, headerKey: String, headerValue: T, payload: APIRequest.Params)
Method to send an api request with a payload formatted in
"JSON"
and with a single headerLink copied to clipboard
open fun sendPayloadedAPIRequest(requestUrl: String, method: APIRequest.RequestMethod, payload: APIRequest.Params)
open fun sendPayloadedAPIRequest(requestUrl: String, method: APIRequest.RequestMethod, payload: MultipartBody)
Method to send an api request with a payload
open fun sendPayloadedAPIRequest(requestUrl: String, method: APIRequest.RequestMethod, headers: APIRequest.Headers, payload: APIRequest.Params)
open fun sendPayloadedAPIRequest(requestUrl: String, method: APIRequest.RequestMethod, headers: APIRequest.Headers, payload: MultipartBody)
Method to send an api request with a payload and with different headers
open fun <T> sendPayloadedAPIRequest(requestUrl: String, method: APIRequest.RequestMethod, headerKey: String, headerValue: T, payload: APIRequest.Params)
open fun <T> sendPayloadedAPIRequest(requestUrl: String, method: APIRequest.RequestMethod, headerKey: String, headerValue: T, payload: MultipartBody)
Method to send an api request with a payload and with a single header
Link copied to clipboard
Method to set programmatically timeout for the request
Link copied to clipboard
Method to set the content type of the payload of the request
Link copied to clipboard
Method to set programmatically default error message to return if is not request error
Link copied to clipboard
Method to set the headers of an
"HTTP"
request Link copied to clipboard
private open fun setRequest(requestUrl: String, method: APIRequest.RequestMethod, payload: MultipartBody)
private open fun setRequest(requestUrl: String, method: APIRequest.RequestMethod, payload: APIRequest.Params, isJsonPayload: Boolean)
Method to set up the request details
Link copied to clipboard
Method to get digest
Link copied to clipboard
Method to validate a self-signed SLL certificate and bypass the checks of its validity No-any params required