Options
All
  • Public
  • Public/Protected
  • All
Menu

Generates a new RESTful API using express. This API responds to all verbs declared in HttpVerb.

Note: the middleware router is already bound with bodyParser urlencoded & json.

author

Gerkin

Hierarchy

Index

Constructors

constructor

Properties

Protected _middleware

_middleware: express.Router

Instance of the middleware to be used by the application

se

ApiGenerator.middleware

author

Gerkin

Protected _modelsConfiguration

_modelsConfiguration: _.Dictionary<IModelConfiguration>

Dictionary containing each configured models settings.

author

Gerkin

Accessors

middleware

middleware:

Public getter to retrieve the middleware instance usable by application

se

ApiGenerator.middleware

author

Gerkin

Methods

Protected bind

  • Binds the instance router with each route verbs.

    author

    Gerkin

    Parameters

    • apiNumber: EQueryPlurality

      Number of entities that this router will bind.

    • route: string

      Path to the API endpoint

    • modelName: string

      Name of the model that is targetted.

    Returns void

Protected generateApiMap

  • Generates the API map of the specified endpoint. This is usually used with the options verb.

    Parameters

    • modelApi: IModelConfiguration

      Model api configuration to answer to

    • queryNumber: EQueryPlurality

      The action number to get map for.

    • baseUrl: string

      Base URL of the endpoint (usually taken from the express request).

    Returns object | object

    Object containing the API map.

Protected getRelevantHandlers

  • Gets the handler to use with the provided query configuration. This is used at initialization for short binding.

    Parameters

    Returns (undefined | function | (undefined | function)[])[]

Protected optionsHandler

  • optionsHandler(req: express.Request, res: express.Response): Response
  • Respond to the request with a map of the API.

    author

    Gerkin

    Parameters

    • req: express.Request

      express request to answer to with API map.

    • res: express.Response

      express response which we are responding to.

    Returns Response

    Returns the answered response.

Protected prepareQueryHandling

  • Parse the query and triggers the Diaspora call. This is the main middleware function of this server

    author

    Gerkin

    Parameters

    • apiNumber: EQueryPlurality

      Indicates the type of the query, saying if we are targetting a single or several entitie(s)

    Returns IHookFunction<express.Request>

    The Hook function to add to the router.

Static Protected castToDiasporaApiRequest

Static Protected deleteHandler

Static Protected findHandler

Static Protected getLoggableDiasporaApi

Static Protected insertHandler

Static parseQuery

  • parseQuery(queryObj: object): object
  • Parse a query string to separate options from search clause.

    author

    Gerkin

    Parameters

    • queryObj: object

      Query string to parse

    Returns object

    A hash with options & search clause separated

    • options: QueryOptions
    • raw: object
    • where: SelectQuery | SelectQueryCondition

Static Protected replaceHandler

Static Protected respondError

  • Respond to the request with an error code

    author

    Gerkin

    Parameters

    • req: IDiasporaApiRequest<IDiasporaApiRequestDescriptorPreParse>

      Parsed request to answer to

    • res: express.Response

      express response object related to the request

    • Optional error: Error

      Error to return to the client.

    • Optional status: undefined | number

      Status code to answer with. If not provided, it is guessed depending on the error.

    Returns void

Static Protected respondMaybeEmptySet

  • respondMaybeEmptySet(res: express.Response, set: Set, responseCode?: EHttpStatusCode): Response
  • Responds to the request with either an empty array or the set

    author

    Gerkin

    Parameters

    • res: express.Response

      The express response to respond to.

    • set: Set

      The set to send to the client.

    • Default value responseCode: EHttpStatusCode = EHttpStatusCode.Ok

      The HTTP status code to send.

    Returns Response

Static Protected respondMaybeNoEntity

  • respondMaybeNoEntity(res: express.Response, entity: Entity | null, responseCode?: EHttpStatusCode): Response
  • Responds to the request with either undefined or the entity

    author

    Gerkin

    Parameters

    • res: express.Response

      The express response to respond to.

    • entity: Entity | null

      The entity to send to the client.

    • Default value responseCode: EHttpStatusCode = EHttpStatusCode.Ok

      The HTTP status code to send.

    Returns Response

Static setIdFromIdHash

  • setIdFromIdHash(entity: Entity): null | IRawEntityAttributes
  • Adds the ID of the entity to the JSON to send to the client. This property is usually not stored in the entity's attributes hash, so we manually add it here.

    author

    Gerkin

    Parameters

    • entity: Entity

      Entity to cast to JSON with ID

    Returns null | IRawEntityAttributes

    The entity attributes, with the ID defined.

Static Protected updateHandler

Object literals

Static Protected handlers

handlers: object

Hash of espress middlewares to bind to router.

author

Gerkin

_delete

_get

_patch

_post

_put

delete

get

patch

post

put

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc