Manual Reference Source Test
import PopApi from 'pop-api/src/PopApi.js'
public class | source

PopApi

The PopApi class with the middleware pattern.

Test:

Static Member Summary

Static Public Members
public static

app: $Application

The application instance for the PopApi framework.

public static

The database connection.

public static

The debugger for extra output.

public static

The arguments passed down to the logger middleware.

Static Private Members
private static

A map of the installed plugins.

Static Method Summary

Static Public Methods
public static

async init(options: Object, middlewares: Array<Function>): Promise<PopApi, Error>

The setup for the base framework.

public static

use(Plugin: Function, args: Object): Promise<PopApi>

Register middleware for the PopApi framework.

Static Public Members

public static app: $Application source

The application instance for the PopApi framework.

Test:

public static database: Database source

The database connection.

public static debug: Function source

The debugger for extra output.

Test:

public static loggerArgs: Object source

The arguments passed down to the logger middleware.

Static Private Members

private static _installedPlugins: Map source

A map of the installed plugins.

Test:

Static Public Methods

public static async init(options: Object, middlewares: Array<Function>): Promise<PopApi, Error> source

The setup for the base framework.

Params:

NameTypeAttributeDescription
options Object
  • nullable: false

The options for the framework.

options.app Express
  • optional
  • default: PopApi.app
  • nullable: false

The web framework instance you want to use.

options.controllers Array<Object>
  • nullable: false

The controllers to register.

options.name string
  • nullable: false

The name for your API.

options.version string
  • nullable: false

The version of your API.

options.logDir string
  • nullable: true

The directory to store the log files in.

options.hosts Array<string>
  • optional
  • nullable: true

The hosts of the database cluster.

options.dbPort number
  • optional
  • nullable: true

The port the database is on.

options.username string
  • optional
  • nullable: true

The username for the database connection.

options.password string
  • optional
  • nullable: true

The password for the database connection.

options.serverPort number
  • optional
  • nullable: true

The port the API will run on.

options.workers number
  • optional
  • nullable: true

The number of workers for the API.

options.opts Object
  • optional
  • nullable: true

Additionl options for custom middlewares.

middlewares Array<Function>
  • nullable: false

The list of middlewares to use. The order of the middlewares is important.

Return:

Promise<PopApi, Error>

The initialized PopApi instance.

Test:

public static use(Plugin: Function, args: Object): Promise<PopApi> source

Register middleware for the PopApi framework.

Params:

NameTypeAttributeDescription
Plugin Function
  • nullable: false

The plugin to use.

args Object
  • nullable: false

The arguments passed down to the constructor of the plugin.

Return:

Promise<PopApi>

The PopApi instance with the installed plugins.

Test: