Home Reference Source

Function

Static Public Summary
public

Create routes by sync callback

public

Convert original deep routes to flat object

public

Check is correct routes passed

since 0.7.0
public

printRoutes(routes: RestRoutes, realPrint: boolean): string[]

Print routes to console and string

Static Public

public createRest(creator: function(r: Maker): null): RestRoutes source

import {createRest} from 'createrest/lib'

Create routes by sync callback

Params:

NameTypeAttributeDescription
creator function(r: Maker): null

Callback

Return:

RestRoutes

Routes object

public flattenRoutes(routes: RestRoutes): object source

import {flattenRoutes} from 'createrest/lib/flatten'

Convert original deep routes to flat object

Params:

NameTypeAttributeDescription
routes RestRoutes

Original routes from createRest()

Return:

object

Flattened routes object

Example:

const handler = () => {}
const routes = createRest(r => { r.get('foo', handler) })
const flatRoutes = flattenRoutes(routes)

test.deepEqual(
  flatRoutes,
  {
    '/foo/': {
      GET: [handler],
    },
  },
)

public isCreateRestInstance(routes: RestRoutes): boolean since 0.7.0 source

import {isCreateRestInstance} from 'createrest/lib'

Check is correct routes passed

Params:

NameTypeAttributeDescription
routes RestRoutes

Return:

boolean

public printRoutes(routes: RestRoutes, realPrint: boolean): string[] source

import {printRoutes} from 'createrest/lib/printer'

Print routes to console and string

Params:

NameTypeAttributeDescription
routes RestRoutes
realPrint boolean

Return:

string[]

Lines of the printed routes