Options
All
  • Public
  • Public/Protected
  • All
Menu

Realm Object Server API docs

Index

Enumerations

Classes

Interfaces

Type aliases

Functions

Type aliases

HTTPMethod

HTTPMethod: "all" | "get" | "put" | "post" | "delete" | "head" | "options" | "trace" | "patch"

A union type of the HTTP methods ROS supports out of the box.

IInstantValuesResponse

IInstantValuesResponse: object

The response that the service sends when metrics are requested

Type declaration

  • [metricName: string]: object[]

Functions

Address

  • Address(): (Anonymous function)
  • A decorator that designates a function that returns the address of the service. Use this if you want to provide custom service address (by default, it will resolve to the http server's address). The returned object must be of the { address: string, port: string } type.

    Returns (Anonymous function)

All

  • All(path: string, config?: object): (Anonymous function)
  • A decorator describing an HTTP request with any verb. Apply this on any method in a service to expose it as an HTTP request handler for the specified path.

    see

    http://expressjs.com/en/guide/routing.html

    Parameters

    • path: string

      The relative path this method will bind to. You can specify parameters by prefixing them with :, e.g. /getresource/:id will populate the id parameter in the request.params object.

    • Default value config: object = {}

    Returns (Anonymous function)

BaseRoute

  • BaseRoute(path: string, config?: object): (Anonymous function)
  • A decorator describing the base route of a service. Apply this on the service class to prefix all routes with the provided path. For example, a /me route on a service with BaseRoute('/users') applied will resolve to the url http://my-server:9080/users/me.

    Parameters

    • path: string

      The relative route to this service, e.g. /users.

    • Default value config: object = { allowAnonymous: true }

    Returns (Anonymous function)

Body

  • Body(keyPath?: string): (Anonymous function)
  • A decorator to parse the incoming req.body from an express call. You can supply an optional keyPath. If the keyPath is not supplied the entire JSON payload will be piped in to the argument

    example
    
     @Post('/')
     private async createUser(
       @Body('username') username: string,
       @Body('password') password: string,
       @Body('metadata.email') email: string
     ) {}
    

    Parameters

    • Optional keyPath: string

      An optional key path of the json. It can be either a string or an array of strings You can delimit keyPaths with a '.' notation. For more information see lodash's get function https://lodash.com/docs/latest#get.

    Returns (Anonymous function)

Cors

  • Cors(path: string, options?: CorsOptions): (Anonymous function)
  • A decorator that allows you to customize the CORS options for a service.

    Parameters

    • path: string

      The path to which the CorsOptions will be applied.

    • Default value options: CorsOptions = null

      Configuration options for the origin, headers, maxAge, and so on.

    Returns (Anonymous function)

Delete

  • Delete(path: string, config?: object): (Anonymous function)
  • A decorator describing an HTTP DELETE request. Apply this on any method in a service to expose it as an HTTP request handler for the specified path.

    see

    http://expressjs.com/en/guide/routing.html

    Parameters

    • path: string

      The relative path this method will bind to. You can specify parameters by prefixing them with :, e.g. /getresource/:id will populate the id parameter in the request.params object.

    • Default value config: object = {}

    Returns (Anonymous function)

Get

  • Get(path: string, config?: object): (Anonymous function)
  • A decorator describing an HTTP GET request. Apply this on any method in a service to expose it as an HTTP request handler for the specified path.

    see

    http://expressjs.com/en/guide/routing.html

    Parameters

    • path: string

      The relative path this method will bind to. You can specify parameters by prefixing them with :, e.g. /getresource/:id will populate the id parameter in the request.params object.

    • Default value config: object = {}

    Returns (Anonymous function)

Head

  • Head(path: string, config?: object): (Anonymous function)
  • A decorator describing an HTTP HEAD request. Apply this on any method in a service to expose it as an HTTP request handler for the specified path.

    see

    http://expressjs.com/en/guide/routing.html

    Parameters

    • path: string

      The relative path this method will bind to. You can specify parameters by prefixing them with :, e.g. /getresource/:id will populate the id parameter in the request.params object.

    • Default value config: object = {}

    Returns (Anonymous function)

HeadBuffer

  • HeadBuffer(): (Anonymous function)
  • Used to explicitly pipe in the head Buffer object, useful for upgrading handlers for websockets.

    Returns (Anonymous function)

Headers

  • Headers(keyPath?: string | string): (Anonymous function)
  • A decorator to parse the incoming req.headers from an express call. You can supply an optional keyPath. If the keyPath is not supplied the entire JSON payload will be piped in to the argument

    example
    
     @Get('/')
     private async getUser(
       @Headers('My-Custom-Header') customHeader: string
     ) {}
    

    Parameters

    • Optional keyPath: string | string

      An optional key path of the json. It can be either a string or an array of strings You can delimit keyPaths with a '.' notation. For more information see lodash's get function https://lodash.com/docs/latest#get.

    Returns (Anonymous function)

MiddlewaresBefore

  • MiddlewaresBefore(...middlewares: RequestHandler[]): (Anonymous function)
  • A descriptor, indicating which middlewares should be executed before executing the HTTP handler. It can be applied on the entire service or on a single route.

    example
    
     const ips = ['127.0.0.1'];
     const middleware = ipfilter(ips, {mode: 'allow'});
    
     @BaseRoute('/cars')
     @MiddlewaresBefore(middleware)
     class CarsService {
         // entire service is available only for the whitelisted Ips
     }
    
     @BaseRoute('/users')
     class UsersService {
         @Delete('/:id')
         @MiddlewaresBefore(middleware)
         deleteUser() {
             // Only whitelisted Ips will enter here
         }
    
         @Get('/')
         getUsers() {
             // Any Ip can request this
         }
     }
    

    Parameters

    • Rest ...middlewares: RequestHandler[]

      A collection of middlewares that will be executed before the service method.

    Returns (Anonymous function)

Next

  • Next(): (Anonymous function)
  • Used to explicitly pipe in the express Next object. Calling next will immediately defer to the next route. Any responses will be ignored.

    example
    
     @Post('/cars')
     private async createCar(@Next() next: () => void) {
       next();
     }
    

    Returns (Anonymous function)

Options

  • Options(path: string, config?: object): (Anonymous function)
  • A decorator describing an HTTP OPTIONS request. Apply this on any method in a service to expose it as an HTTP request handler for the specified path.

    see

    http://expressjs.com/en/guide/routing.html

    Parameters

    • path: string

      The relative path this method will bind to. You can specify parameters by prefixing them with :, e.g. /getresource/:id will populate the id parameter in the request.params object.

    • Default value config: object = {}

    Returns (Anonymous function)

Params

  • Params(keyPath?: string | string[]): (Anonymous function)
  • Parses an express param from the url. If the keyPath is not supplied the entire set of params will be piped in as dictionary.

    example
    
     @Get('/cars/:carId')
     private async getCar(@Params('carId') carId: string) {}
    

    Parameters

    • Optional keyPath: string | string[]

      the key of the param to parse, it should not contain a dash (-). You can delimit keyPaths with a '.' notation. For more information see lodash's get function https://lodash.com/docs/latest#get.

    Returns (Anonymous function)

Patch

  • Patch(path: string, config?: object): (Anonymous function)
  • A decorator describing an HTTP PATCH request. Apply this on any method in a service to expose it as an HTTP request handler for the specified path.

    see

    http://expressjs.com/en/guide/routing.html

    Parameters

    • path: string

      The relative path this method will bind to. You can specify parameters by prefixing them with :, e.g. /getresource/:id will populate the id parameter in the request.params object.

    • Default value config: object = {}

    Returns (Anonymous function)

Post

  • Post(path: string, config?: object): (Anonymous function)
  • A decorator describing an HTTP POST request. Apply this on any method in a service to expose it as an HTTP request handler for the specified path.

    see

    http://expressjs.com/en/guide/routing.html

    Parameters

    • path: string

      The relative path this method will bind to. You can specify parameters by prefixing them with :, e.g. /getresource/:id will populate the id parameter in the request.params object.

    • Default value config: object = {}

    Returns (Anonymous function)

Put

  • Put(path: string, config?: object): (Anonymous function)
  • A decorator describing an HTTP PUT request. Apply this on any method in a service to expose it as an HTTP request handler for the specified path.

    see

    http://expressjs.com/en/guide/routing.html

    Parameters

    • path: string

      The relative path this method will bind to. You can specify parameters by prefixing them with :, e.g. /getresource/:id will populate the id parameter in the request.params object.

    • Default value config: object = {}

    Returns (Anonymous function)

Query

  • Query(keyPath?: string): (Anonymous function)
  • Parses an express query from the url. If the keyPath is not supplied the entire set of query arguments will be piped in as dictionary.

    example
    
     // This will resolve the arguments for e.g. /cars?color=red&brand=toyota
     @Get('/cars')
     private async getCars(
       @Query('color') color: string,
       @Query('brand') brand: string
     ) {}
    

    Parameters

    • Optional keyPath: string

      the key of the param to parse You can delimit keyPaths with a '.' notation. For more information see lodash's get function https://lodash.com/docs/latest#get.

    Returns (Anonymous function)

Request

  • Request(): (Anonymous function)
  • Used to explicitly pipe in the express Request or http.IncomingRequest object.

    see

    http://expressjs.com/en/api.html#req

    example
    
     @Post('/cars')
     private async createCar(@Request() req: any) {
       // read data from the express request, e.g.
       const body = req.body;
     }
    

    Returns (Anonymous function)

Response

  • Response(): (Anonymous function)
  • Used to explicitly pipe in the express Response object.

    see

    http://expressjs.com/en/api.html#res

    example
     @Post('/cars')
     private async createCar(
       @Request() req: any,
       @Response() res: any
     ) {
       // Modify the response, e.g.
       res.set('ETag', '12345');
     }
    

    Returns (Anonymous function)

ServeStatic

  • ServeStatic(route: string, staticRoot: string): (Anonymous function)
  • A decorator to designate a service as being able to serve static files.

    Parameters

    • route: string

      The route to which the router can attach.

    • staticRoot: string

      The path to the static directory or assets, e.g. /webserver/images.

    Returns (Anonymous function)

ServerStarted

  • ServerStarted(): (Anonymous function)
  • A decorator to designate a function in your service as a callback for when the http server is bootstrapped and operational. It will be invoked by ROS with the Server as an argument.

    Returns (Anonymous function)

ServiceName

  • ServiceName(name: string): (Anonymous function)
  • A decorator describing the name of a service. You must apply this to the service class if you want the service to be discoverable by other services by calling Discovery.find.

    Parameters

    • name: string

      The name of the service that will be used as a key by the discovery mechanism. It is recommended that it is unique to make discovery easier.

    Returns (Anonymous function)

Socket

  • Socket(): (Anonymous function)
  • Used to explicitly pipe in the Socket object, useful for upgrading handlers for websockets.

    Returns (Anonymous function)

Start

  • Start(): (Anonymous function)
  • A decorator to designate a function in your service as a bootstrapping function. It will be invoked when the service is created and the Server will be passed in as argument. Note that at the time this function is invoked, the http server may not have started yet.

    Returns (Anonymous function)

Stop

  • Stop(): (Anonymous function)
  • A decorator to designate a function in your service as a cleanup function. It will be invoked when the service must be stopped and gives you a chance to clean up any resources, associated with the service. If the resource cleanup depends on other services, use Stopping instead.

    Returns (Anonymous function)

Stopping

  • Stopping(): (Anonymous function)
  • A decorator to designate a function in your service as a pre-cleanup function. It will be invoked before the Stop function and should be used to cleanup resources that depend on other services.

    Returns (Anonymous function)

Tags

  • Tags(tags: string[]): (Anonymous function)
  • A decorator describing a set of tags associated with a service. They can then be used to search for them with Discovery.find or Discovery.findAll.

    Parameters

    • tags: string[]

      An array of string tags.

    Returns (Anonymous function)

Trace

  • Trace(path: string, config?: object): (Anonymous function)
  • A decorator describing an HTTP TRACE request. Apply this on any method in a service to expose it as an HTTP request handler for the specified path.

    see

    http://expressjs.com/en/guide/routing.html

    Parameters

    • path: string

      The relative path this method will bind to. You can specify parameters by prefixing them with :, e.g. /getresource/:id will populate the id parameter in the request.params object.

    • Default value config: object = {}

    Returns (Anonymous function)

Unmute

  • Unmute(contextual?: boolean): (Anonymous function)
  • A decorator that designates a function that will be invoked with a logger by ROS. It is the recommended way of injecting a logger in your service.

    Parameters

    • Default value contextual: boolean = true

      An argument, controlling whether a contextual logger will be injected or not. A contextual logger will have its context set to { service: serviceName }, whereas a regular one will have an empty context.

    Returns (Anonymous function)

Upgrade

  • Upgrade(path: string): (Anonymous function)
  • A decorator describing an HTTP UPGRADE request. Apply this on any method in a service to expose it as an HTTP request handler for the specified path.

    see

    http://expressjs.com/en/guide/routing.html

    Parameters

    • path: string

      The relative path this method will bind to. You can specify parameters by prefixing them with :, e.g. /getresource/:id will populate the id parameter in the request.params object.

    Returns (Anonymous function)

isAdminToken

  • isAdminToken(token: Token): boolean
  • A function to check if a token belongs to an admin user.

    Parameters

    • token: Token

      The token to check.

    Returns boolean

    true if the token represents an admin token, false otherwise.