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

@http4t/bidi

Package Overview
Dependencies
Maintainers
4
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@http4t/bidi

NB: This is nowhere near production ready at time of writing.

  • 0.4.119
  • latest
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

Bi-directional routing

NB: This is nowhere near production ready at time of writing.

Goals

HTTP routes that can be shared by clients and server

I should be able to define a route at GET /widgets/{id} and use that route to both:

  • Match a request on the server side, then route it to a handler function
  • Create a request on the client side and pass it to an HttpHandler

By sharing the routes between client and server I avoid bugs with my client sending the wrong shaped requests to my server.

Fully type-safe contracts for both client and server

If I have a route GET /widgets/{widgetId} that returns a json-serialised response body containing a Widget, I want to be able to give my server a handler function that knows nothing about http, like:

(args: {widgetId: string}) => Promise<Widget>

...and have the server destructure the request into that shape and then serialise the function result into an HttpResponse.

On the client side, I want to be able to generate a function with the same signature that takes care of serialising to an HttpRequest, sending to an HttpHandler, then deserialising from HttpResponse.

Examples

See client.test.ts for an example of a complete round trip from client to server and back.

FAQs

Package last updated on 12 Apr 2023

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