Skip to main content

HotAPI

hotstaq / Modules / HotAPI

Class: HotAPI

The API to use.

Hierarchy​

Table of contents​

Constructors​

Properties​

Methods​

Constructors​

constructor​

• new HotAPI(baseUrl, connection?, db?)

Parameters​

NameTypeDefault value
baseUrlstringundefined
connectionHotServer | HotClientnull
dbHotDB<any, any, HotDBSchema>null

Defined in​

HotAPI.ts:78

Properties​

authCredentials​

• authCredentials: any

The authorization credentials to use throughout the application.

Defined in​

HotAPI.ts:58


baseUrl​

• baseUrl: string

The base url for the server.

Defined in​

HotAPI.ts:41


connection​

• connection: HotServer | HotClient

The server connection.

Defined in​

HotAPI.ts:37


createFunctions​

• createFunctions: boolean

If set, this will create the route variables and functions for easy client/server calling.

Defined in​

HotAPI.ts:46


db​

• db: HotDB<any, any, HotDBSchema>

The database connection.

Defined in​

HotAPI.ts:54


executeEventsUsing​

• executeEventsUsing: EventExecutionType

The database connection.

Defined in​

HotAPI.ts:50


onPostRegister​

• onPostRegister: () => Promise<boolean>

Type declaration​

â–¸ (): Promise<boolean>

Executed when the API has finished registering routes. If this function returns false, the server will not start.

Returns​

Promise<boolean>

Defined in​

HotAPI.ts:76


onPreRegister​

• onPreRegister: () => Promise<boolean>

Type declaration​

â–¸ (): Promise<boolean>

Executed when the API is about to start registering routes. If this function returns false, the server will not start.

Returns​

Promise<boolean>

Defined in​

HotAPI.ts:71


routes​

• routes: Object

The database connection.

Index signature​

â–ª [name: string]: HotRoute

Defined in​

HotAPI.ts:66


userAuth​

• userAuth: ServerAuthorizationFunction

The function used for user authentication.

Defined in​

HotAPI.ts:62

Methods​

addRoute​

â–¸ addRoute(route, routeMethod?, executeFunction?): void

Add a route. If this.createFunctions is set to true, this will take the incoming route and create an object in this HotAPI object using the name of the route. If there's any HotRouteMethods inside of the incoming HotRoute, it will create the methods and attach them to the newly created HotRoute object.

Example:

export class Users extends HotRoute
{
constructor (api: FreeLightAPI)
{
super (api.connection, "user");

this.addMethod ("create", this._create, HTTPMethod.POST);
}

protected async _create (req: any, res: any, authorizedValue: any, jsonObj: any, queryObj: any): Promise<any>
{
return (true);
}
}

This in turn could be used like so:

Hot.API.user.create ({});

Additionally it would create the endpoint: http://127.0.0.1:8080/v1/user/create

Parameters​

NameTypeDefault valueDescription
routestring | HotRouteundefinedThe route to add. Can be either a full HotRoute object, or just the route's name. If a HotRoute object is supplied, the rest of the parameters will be ignored.
routeMethodstring | HotRouteMethodnullThe route's method to add. If the route parameter is a string, it will be interpreted as the route's name, and this will be the method added to the new route.
executeFunction(req: any, res: any, authorizedValue: any, jsonObj: any, queryObj: any) => Promise<any>nullThe function to execute when routeMethod is called by the API.

Returns​

void

Defined in​

HotAPI.ts:167


getDB​

â–¸ getDB(): HotDB<any, any, HotDBSchema>

Get the database being used.

Returns​

HotDB<any, any, HotDBSchema>

Defined in​

HotAPI.ts:109


getDBSchema​

â–¸ getDBSchema(): HotDBSchema

Get the database schema being used.

Returns​

HotDBSchema

Defined in​

HotAPI.ts:120


makeCall​

â–¸ makeCall(route, data, httpMethod?): Promise<any>

Make a call to the API.

Parameters​

NameTypeDefault value
routestringundefined
dataanyundefined
httpMethodstring"POST"

Returns​

Promise<any>

Defined in​

HotAPI.ts:343


registerRoute​

â–¸ registerRoute(route): Promise<void>

Register a route with the server.

Parameters​

NameType
routeHotRoute

Returns​

Promise<void>

Defined in​

HotAPI.ts:321


registerRoutes​

â–¸ registerRoutes(): Promise<void>

Register all routes with the server.

Returns​

Promise<void>

Defined in​

HotAPI.ts:330


setDBSchema​

â–¸ setDBSchema(schema): void

Set the database schema for use.

Parameters​

NameType
schemaHotDBSchema

Returns​

void

Defined in​

HotAPI.ts:95