RestOperations

Handles REST services' operations.

Implements: IConfigurable, IReferenceable

Description

The RestOperations class allows you to handle REST services' operations.

Fields

_logger

Composite logger component

protected _logger: CompositeLogger = CompositeLogger()

_counters

Counter component

protected _counters: CompositeCounters = CompositeCounters()

_dependencyResolver

Dependency resolver component

protected _dependencyResolver: DependencyResolver = DependencyResolver()

Instance methods

configure

Configures a component by passing its configuration parameters.

public configure(config: ConfigParams): void

  • config: ConfigParams - configuration parameters to be set.

getCorrelationId

Returns a correlationId from a request

protected getCorrelationId(req: any): any

  • req: any - an HTTP request
  • returns: any - correlationId from a request

getFilterParams

Gets the filter parameters.

protected getFilterParams(req: any): FilterParams

  • req: any - an HTTP request
  • returns: FilterParams - filter paramters

getPagingParams

Gets the paging parameters.

protected getPagingParams(req: any): PagingParams

  • req: any - an HTTP request
  • returns: PagingParams - paging paramters

invoke

Invokes an operation.

public invoke(operation: string): (req: any, res: any) => void

  • operation: string - operation to be invoked
  • returns: (req: any, res: any) => void - operation

sendBadRequest

Sends a bad request error message.

protected sendBadRequest(req: any, res: any, message: string): void

  • req: any - an HTTP request
  • res: any - an HTTP response
  • message: string - message

sendConflict

Sends a conflict error messge

protected sendConflict(req: any, res: any, message: string): void

  • req: any - an HTTP request
  • res: any - an HTTP response
  • message: string - message

sendCreatedResult

Sends a JSON object with the created result.

protected sendCreatedResult(req: any, res: any, result: any): void

  • req: any - an HTTP request
  • res: any - an HTTP response
  • result: any - result to be sent.

sendDeletedResult

Sends the deleted result in JSON format.

protected sendDeletedResult(req: any, res: any, result: any): void

  • req: any - an HTTP request
  • res: any - an HTTP response
  • result: any - execution result or a promise with execution result.

sendEmptyResult

Send an empty result with 204 status code.

protected sendEmptyResult(req: any, res: any): void

  • req: any - an HTTP request
  • res: any - an HTTP response

sendError

Sends an error serialized as ErrorDescription object and appropriate HTTP status code.

protected sendError(req: any, res: any, error: any): void

  • req: any - an HTTP request
  • res: any - an HTTP response
  • error: any - error

sendInternalError

Sends an internal error message

protected sendInternalError(req: any, res: any, message: string): void

  • req: any - an HTTP request
  • res: any - an HTTP response
  • message: any - message

sendNotFound

Sends a not found error message.

protected sendNotFound(req: any, res: any, message: string): void

  • req: any - an HTTP request
  • res: any - an HTTP response
  • message: any - message

sendResult

Sends a result as a JSON object.

protected sendResult(req: any, res: any, result: any): void

  • req: any - an HTTP request
  • res: any - an HTTP response
  • result: any - result

sendServerUnavailable

Sends a server unavailable error message (Status code 503).

protected sendServerUnavailable(req: any, res: any, message: string): void

  • req: any - an HTTP request
  • res: any - an HTTP response
  • message: string - message

sendSessionExpired

Sends a session expired error message (Status code 440).

protected sendSessionExpired(req: any, res: any, message: string): void

  • req: any - an HTTP request
  • res: any - an HTTP response
  • message: string - message

sendUnauthorized

Sends an unauthorized error message.

protected sendUnauthorized(req: any, res: any, message: string): void

  • req: any - an HTTP request
  • res: any - an HTTP response
  • message: string - message

setReferences

Sets the specified references.

public setReferences(references: IReferences): void