Api Testing
Sente includes an API method based on axios allowing you to send requests such as get, post, put, and delete.
Usage
api(<properties>)
let properties = {
{string} [method] - The HTTP method to use for the request (e.g., 'GET', 'POST', 'DELETE', 'PUT'). This parameter is required.
{string} [url] - The URL to send the request to.
{string} [baseURL] - The base URL to use for the request.
{Array|Function} [transformRequest] - Allows changes to the request data before it is sent to the server.
{Array|Function} [transformResponse] - Allows changes to the response data to be made before it is passed to then/catch.
{Object} [headers] - The headers to be sent with the request.
{Object} [params] - The URL parameters to be sent with the request.
{Function} [paramsSerializer] - A function to serialize the params.
{Object} [data] - The data to be sent as the request body.
{number} [timeout] - The number of milliseconds before the request times out. Defaults to `sentedefaultTimeout * 1000`.
{string} [timeoutErrorMessage] - The error message to be displayed if the request times out.
{boolean} [withCredentials] - Indicates whether or not cross-site Access-Control requests should be made using credentials.
{Function} [adapter] - Allows custom handling of requests.
{Object} [auth] - HTTP Basic auth credentials.
{string} [responseType] - The type of data that the server will respond with.
{string} [responseEncoding] - The encoding to use for the response.
{string} [xsrfCookieName] - The name of the cookie to use as a value for xsrf token.
{string} [xsrfHeaderName] - The name of the HTTP header that carries the xsrf token value.
{Function} [onUploadProgress] - A function to handle progress events for uploads.
{Function} [onDownloadProgress] - A function to handle progress events for downloads.
{number} [maxContentLength] - The maximum size of the HTTP response content in bytes.
{Function} [validateStatus] - A function to determine if the response status code is valid.
{number} [maxRedirects] - The maximum number of redirects to follow.
{string} [socketPath] - The path to use for UNIX domain sockets.
{Object} [httpAgent] - The agent to use for HTTP requests.
{Object} [httpsAgent] - The agent to use for HTTPS requests. Defaults to a new https.Agent with `rejectUnauthorized` set to false.
{Object} [proxy] - The proxy configuration.
{Object} [cancelToken] - A cancel token to cancel the request.
{boolean} [decompress] - Indicates whether or not the response body should be decompressed.
}
"Get" Request with basic auth credentials
/* LIBRARIES
*************/
const { sente } = require('#libraries');
const { api } = sente;
/* TEST FLOW
*************/
test = async () => {
// Get Request with basic auth credentials
let apiProperties = {
method: 'GET',
url : "<api url>", // https://xxx.com.tr/api"
auth: {
username: "<username>",
password: "<password>"
}
}
// send request
let request_result = await api(apiProperties);
// print status
log(request_result.status)
"POST" Request with basic auth credentials
/* LIBRARIES
*************/
const { sente } = require('#libraries');
const { api } = sente;
/* TEST FLOW
*************/
test = async () => {
// Post Request with basic auth credentials
let apiProperties = {
method: 'POST',
url : "<api url>", // https://xxx.com.tr/api"
auth: {
username: "<username>",
password: "<password>"
},
data: {
parameter_1: '<value>' ,
parameter_2: '<value>' ,
parameter_n: '<value>'
}
}
// send request
let request_result = await api(apiProperties);
// print status
log(request_result.status)
Last updated