0.1.8 • Published 6 months ago

pitico v0.1.8

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

Pitico NPM version js-standard-style

Pitico is a tiny wrapper for the Node.js standard library http module.

It is intended for writing really small internal API servers where all you need is moving JSON payloads in and out, and think even Fastify might be overkill for your needs. It is of course inspired by Fastify, and offers a very limited degree of compatibility at the moment.

Features

  • Ergonomic API for defining JSON endpoints
    • Along with their request and response schemas
    • Using jsontypedef under the hood for setting types
  • Minimal compatibility with Fastify plugins
    • register() works but will completely ignore encapsulation
    • decorate() extends the server instance
    • decorateRequest() extends http.IncomingMessage directly
    • inject() behaves the same way for testing
  • Ajv-optimized JSON parsing and validation based on JTD schemas
  • Ajv-optimized JSON serialization based on JTD schemas

Limitations

It is a radically minimal server so a few contraints are embraced:

  • Only JSON request payloads supported.
  • No URL parsing, routing is just absolute paths in a Map.

Install

npm i pitico --save

Usage

Bootstrap: server.js

import Pitico from 'pitico'

import * as serialize from './serialize.js'

const server = Pitico([serialize])

await server.listen({ port: 3000 })

Route: serialize.js

export const path = '/serialize'

export default (server, { object, string }) => ({
  parse: object({
    foobar: string()
  }),
  serialize: object({
    foobar: string(),
  }),
  handle (req, res) {
    return {
      foobar: req.body.foobar,
    }
  },
})

See jsontypedef for the full list of helpers available for defining JTD types.

License

MIT

0.1.8

6 months ago

0.1.7

6 months ago

0.1.6

7 months ago

0.1.5

10 months ago

0.1.4

11 months ago

0.1.3

11 months ago

0.1.1

11 months ago

0.1.0

11 months ago