HotAPI
Class: HotAPI
The API to use.
Hierarchy​
HotAPI
↳
HotTesterAPI
Table of contents​
Constructors​
Properties​
- authCredentials
- baseUrl
- connection
- createFunctions
- db
- executeEventsUsing
- onPostRegister
- onPreRegister
- routes
- userAuth
Methods​
Constructors​
constructor​
• new HotAPI(baseUrl
, connection?
, db?
)
Parameters​
Name | Type | Default value |
---|---|---|
baseUrl | string | undefined |
connection | HotServer | HotClient | null |
db | HotDB <any , any , HotDBSchema > | null |
Defined in​
Properties​
authCredentials​
• authCredentials: any
The authorization credentials to use throughout the application.
Defined in​
baseUrl​
• baseUrl: string
The base url for the server.
Defined in​
connection​
• connection: HotServer
| HotClient
The server connection.
Defined in​
createFunctions​
• createFunctions: boolean
If set, this will create the route variables and functions for easy client/server calling.
Defined in​
db​
• db: HotDB
<any
, any
, HotDBSchema
>
The database connection.
Defined in​
executeEventsUsing​
• executeEventsUsing: EventExecutionType
The database connection.
Defined in​
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​
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​
routes​
• routes: Object
The database connection.
Index signature​
â–ª [name: string
]: HotRoute
Defined in​
userAuth​
• userAuth: ServerAuthorizationFunction
The function used for user authentication.
Defined in​
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​
Name | Type | Default value | Description |
---|---|---|---|
route | string | HotRoute | undefined | The 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. |
routeMethod | string | HotRouteMethod | null | The 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 > | null | The function to execute when routeMethod is called by the API. |
Returns​
void
Defined in​
getDB​
â–¸ getDB(): HotDB
<any
, any
, HotDBSchema
>
Get the database being used.
Returns​
HotDB
<any
, any
, HotDBSchema
>
Defined in​
getDBSchema​
â–¸ getDBSchema(): HotDBSchema
Get the database schema being used.
Returns​
Defined in​
makeCall​
â–¸ makeCall(route
, data
, httpMethod?
): Promise
<any
>
Make a call to the API.
Parameters​
Name | Type | Default value |
---|---|---|
route | string | undefined |
data | any | undefined |
httpMethod | string | "POST" |
Returns​
Promise
<any
>
Defined in​
registerRoute​
â–¸ registerRoute(route
): Promise
<void
>
Register a route with the server.
Parameters​
Name | Type |
---|---|
route | HotRoute |
Returns​
Promise
<void
>
Defined in​
registerRoutes​
â–¸ registerRoutes(): Promise
<void
>
Register all routes with the server.
Returns​
Promise
<void
>
Defined in​
setDBSchema​
â–¸ setDBSchema(schema
): void
Set the database schema for use.
Parameters​
Name | Type |
---|---|
schema | HotDBSchema |
Returns​
void