1.14.0 • Published 6 years ago

dl-pico v1.14.0

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

dl-pico

Microservice module. Example in test/index.ts.

PicoServer

const server = new PicoServer(name?: string);

Create a new server with a name. The name is for debugging/logging purposes only.

server.receive<IBodyType>(method: 'get' | 'patch' | 'post' | 'delete' | 'put', path: string, cb: (req: express.Request & { payload?: T, file?: Buffer }, res: express.Response) => void, internal = false, raw = false, headerBody = false)

Create an endpoint.

  • method: HTTP method to use
  • path: Internal HTTP path
  • cb: callback, with attached payload or file if provided
  • internal: prepend internal path to path
  • raw: if the body is to be read as a Buffer

If raw is set, payload will be populated by the json-decoded header x-body if present.

server.finalize()

Listen on the server's port.

PicoRequest

PicoRequest = async<T>(method: string, server: string, uri: string, internal = false, headers?: any, body?: any, json = true)

Returns a promise of type T. T will have an error field added; if it is non-null there was an error.

  • method: the http method (GET, POST etc)
  • server: the root endpoint
  • url: the path from the PicoServer
  • internal: whether the path is internal or not
  • headers: object containing additional headers
  • body: object to be used as the body. Should be a plain javascript object
  • json: If the body is an object
1.14.0

6 years ago

1.13.0

6 years ago

1.12.0

6 years ago

1.11.0

6 years ago

1.10.1

6 years ago

1.10.0

6 years ago

1.9.0

6 years ago

1.8.1

6 years ago

1.8.0

6 years ago

1.7.0

6 years ago

1.6.0

6 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago