-
Notifications
You must be signed in to change notification settings - Fork 0
Configuring
type RaceConditionHandlerParams = "abort-previous" | "enqueue-new";
interface ClientConfig {
onNewRequest?: RaceConditionHandlerParams; // defaults to "enqueue-new"
acceptStatusCodes?: number[];
isDebugMode?: boolean; // defaults to false
}-
onNewRequest: This property determines how to deal with race conditions.
You can learn what these 'race conditions' are in the race conditions page.
-
acceptStatusCodes: This property determines which status codes are expected with response.
isSuccessis set totrueif status code from the response is among this expected status codes. By default, the requester expect this status codes:const POSSIBLE_STATUS_CODES: number[] = [200, 201, 202, 203, 204, 205, 206];
The additional values we passed to this property are added to this list of status codes above.
-
isDebugMode: Debug mode logs the request process to the console. This property determines if the debug mode is toggled.
type Methods = "GET" | "HEAD" | "OPTIONS" | "TRACE" | "PUT" | "DELETE" | "POST" | "PATCH" | "CONNECT";
type HttpProtocols = "http" | "https";
interface RequestConfig {
url: {
protocol?: HttpProtocols; // defaults to "http"
baseURL: string;
port?: number;
endpoint: object | string;
query?: Record<string, string>;
};
method: Methods;
header?: {
contentType?: string; // defaults to "Content-Type: application/json"
responseLang?: string;
headers?: Record<string, string>; // defaults to an empty object
};
auth?: {
accessToken?: string | number;
includeCookies?: boolean; // defaults to false
};
}-
urlsection-
protocol (optional): This is the protocol for the request and accepts
httporhttps. It defaults tohttp. -
baseUrl (required): This is the base of the url we will send the request to. It should not contain protocol, port, endpoint etc. Basically it should only be the entrypoint of the server like
example.com/api. -
port (optional): This is the port value of the url. It doesn't have a default value and is not set by default.
-
endpoint (required): This is the endpoint/route that comes after the base url. It can be a simple string like
/auth/user/register, or can be an object. If an object is passed to the property, the requester builds an endpoint using the values from the object (not the keys).... endpoint: { route: "auth", subroute: "user", action: "register", }, ...
In this example, the generated endpoint is
/auth/user/register.
- query (optional): This is query that comes after the endpoint. It doesn't have a default value and is not set by default.
-
-
method(required): This is the request's method likeGET,POST, etc. -
headersection-
contentType (optional): This property specifies the media type of the request body. It defaults to
application/json. Thus, specifying it explicitly is not necessary. -
responseLang (optional): This property sets the
Accept-Languageheader to inform the server that we expect a response in this language. This option is mostly for servers that have a translation feature. - headers (optional): This property is for the extra headers we want to include with the request.
-
contentType (optional): This property specifies the media type of the request body. It defaults to
-
authsection-
accessToken (optional): This property sets the
Authorizationheader of the request by adding a bearer token (Bearer <tokenValue>). It doesn't have a default value and is not set by default. -
includeCookies (optional): This property determines whether we want to send the cookies from the browser to the server with our request. It defaults to
false
-
accessToken (optional): This property sets the