Skip to main content

FreeqApi

Defined in: utils/FreeqApi.ts:15

Provides static methods for making HTTP requests to the Freeq API.

Remarks

Set FreeqApi.baseUrl and FreeqApi.token before making requests. Supports GET, POST, PUT, DELETE and PATCH methods with optional response transformation.

Example

FreeqApi.baseUrl = "https://api.freeq.io";
FreeqApi.token = "your-jwt-token";
const user = await FreeqApi.get<User>("/api/v1/users/1", data => new User(data.id, data.name));

Constructors

Constructor

new FreeqApi(): FreeqApi;

Returns

FreeqApi

Properties

baseUrl

static baseUrl: string;

Defined in: utils/FreeqApi.ts:17

The base URL for API requests.


sessionDetails

static sessionDetails: any;

Defined in: utils/FreeqApi.ts:21

The session details returned upon signing in.


token

static token: undefined | string;

Defined in: utils/FreeqApi.ts:19

The authentication token for API requests.

Methods

delete()

static delete<T>(
endpoint,
transform?,
headers?): Promise<T>;

Defined in: utils/FreeqApi.ts:90

Makes a DELETE request to the specified endpoint.

Type Parameters

T

T

Parameters

endpoint

string

The API endpoint.

transform?

(data) => T

Optional function to transform the response data.

headers?

Record<string, string>

Optional custom headers.

Returns

Promise<T>

A promise that resolves to the transformed response.


get()

static get<T>(
endpoint,
transform?,
headers?): Promise<T>;

Defined in: utils/FreeqApi.ts:41

Makes a GET request to the specified endpoint.

Type Parameters

T

T

Parameters

endpoint

string

The API endpoint.

transform?

(data) => T

Optional function to transform the response data.

headers?

Record<string, string>

Optional custom headers.

Returns

Promise<T>

A promise that resolves to the transformed response.


getCurrent()

static getCurrent(
id,
name,
defaultValue): any;

Defined in: utils/FreeqApi.ts:30

Returns the appropriate identifier, substituting "current" or "me" if the ID is 0 or matches the session detail.

Parameters

id

any

The identifier to check.

name

string

The name of the session detail to compare against.

defaultValue

string

The value to return if the ID is 0 or matches the session detail.

Returns

any

The original ID or the default value.


patch()

static patch<T>(
endpoint,
transform?,
headers?): Promise<T>;

Defined in: utils/FreeqApi.ts:111

Makes a PATCH request to the specified endpoint.

Type Parameters

T

T

Parameters

endpoint

string

The API endpoint.

transform?

(data) => T

Optional function to transform the response data.

headers?

Record<string, string>

Optional custom headers.

Returns

Promise<T>

A promise that resolves to the transformed response.


post()

static post<T>(
endpoint,
data?,
transform?,
headers?): Promise<T>;

Defined in: utils/FreeqApi.ts:57

Makes a POST request to the specified endpoint.

Type Parameters

T

T

Parameters

endpoint

string

The API endpoint.

data?

any

The request body data.

transform?

(data) => T

Optional function to transform the response data.

headers?

Record<string, string>

Optional custom headers.

Returns

Promise<T>

A promise that resolves to the transformed response.


put()

static put<T>(
endpoint,
data?,
transform?,
headers?): Promise<T>;

Defined in: utils/FreeqApi.ts:74

Makes a PUT request to the specified endpoint.

Type Parameters

T

T

Parameters

endpoint

string

The API endpoint.

data?

any

The request body data.

transform?

(data) => T

Optional function to transform the response data.

headers?

Record<string, string>

Optional custom headers.

Returns

Promise<T>

A promise that resolves to the transformed response.