Socket
Book a DemoInstallSign in
Socket

reverse-client

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reverse-client

An auto-generated HTTP(S) API client for applications built using the `reverse` router

latest
npmnpm
Version
0.2.2
Version published
Maintainers
1
Created
Source

reverse-client

An auto-generated HTTP(S) API client for applications built using the reverse router.

Installation

npm install reverse-client --save

Usage

const http = require('http')
const reverse = require('reverse')
const reverseClient = require('reverse-client')

const router = reverse`
  GET /bar getBar
  GET /foo/${reverse.param('id', String)} getFoo
`({
  getBar: () => console.log('getBar'),
  getFoo: (id) => console.log('getFoo', id),
})

const server = http.createServer((req, res) => {
  console.log(req.method, req.url)
  const match = router.match(req.method, req.url)
  match.controller[match.name](match.context)
  res.writeHead(200)
  res.end()
})
server.listen(7676)

const client = reverseClient(router, 'http://127.0.0.1:7676')
client.getBar()
client.getFoo(10)

Keywords

reverse

FAQs

Package last updated on 15 Jan 2020

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