Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fluture-fastify

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fluture-fastify

Create Fastify handlers using Futures

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Fluture Fastify

Build Status

Create Fastify handlers using Futures from Fluture.

Usage

npm install --save fluture fluture-fastify

Allows using pure functions as Fastify handlers. Expects actions to return Futures and the reply to be decorated with a property locals that will be passed to every action as its second argument.

import {handler, Typed} from 'fluture-fastify';
import {after} from 'fluture';
import createApp from 'fastify';

const app = createApp({logger: true});

const Json = Typed ('application/json; charset=utf-8');
const action = (req, {number}) => after (100, Json (200, number));

app.decorateReply ('locals', {number: 42});
app.get ('/number', handler ('getNumber', action));

app.listen (3000, '0.0.0.0');

API

Responses

Typed :: (Str, Num, Any) -⁠> Response a

A typed response requires status code, some content and the content type. The type defines how the value is serialized. In order to see all the possible combinations see reply.send docs.

Plain text
const Plain = Typed ('text/plain; charset=utf-8');

Plain (200, 'Number 42');
Json
const Json = Typed ('application/json; charset=utf-8');

Json (200, {number: 42});
Stream
const Stream = Typed ('application/octet-stream');

Stream (200, createReadStream ('file', 'utf8'));

Serialized :: (b -⁠> c, Str, Num, b) -⁠> Response a

A typed response with a custom serializer.

const Proto = Serialized (protoBuf.serialize, 'application/x-protobuf');

Proto (200, new protoBuf ());

Redirect :: (Num, Str) -⁠> Response a

A redirection consisting of a URL and the status code.

Empty :: Response a

An empty response with status code 204.

NotFound :: Response a

The default NotFound response.

Functions

handler :: (Str, (Req, a) -⁠> Future b (Response a)) -⁠> (Req, Res a) -⁠> undefined

Creates a Fastify handler from a named action. The action needs to either resolve to a Response or reject with anything. The rejected value will be send as a response with status code 500. The status code can be overwritten by rejecting with an Error that contains the prop statusCode.

Keywords

FAQs

Package last updated on 13 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc