dl-pico
TypeScript icon, indicating that this package has built-in type declarations

1.14.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i dl-pico

Weekly Downloads

1

Version

1.14.0

License

MIT

Unpacked Size

45.2 kB

Total Files

8

Last publish

Collaborators

  • disseminate