A tiny wrapper for the Node.js http module implementing JTD-based validation and JSON serialisation.
undefinedPitico 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.
jsontypedef under the hood for setting typesregister() works but will completely ignore encapsulationdecorate() extends the server instancedecorateRequest() extends http.IncomingMessage directlyinject() behaves the same way for testingIt is a radically minimal server so a few contraints are embraced:
Map.npm i pitico --save
import Pitico from 'pitico'
import * as serialize from './serialize.js'
const server = Pitico([serialize])
await server.listen({ port: 3000 })
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.
MIT
We use cookies
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.