npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

http-json-proxy

v1.0.1

Published

Simple HTTP JSON proxy

Downloads

10

Readme

http-json-proxy

Build Status bitHound Overall Score bitHound Dependencies bitHound Code

Simple HTTP JSON proxy.

This proxy can be used as a middleman in between a HTTP JSON API server and a client to monitor the requests, responses and even modify on the fly any of those.

Installation

$ npm install --global http-json-proxy

Usage

The following command will spin up a proxy server that will forward all requests to a locally installed Ethereum node and will log to console each JSON RPC call with the corresponding response:

$ http-json-proxy -p 18545 -t http://localhost:8545
Proxy for http://localhost:8545 listening on port 18545

Then, each call will be logged as follows:

--> POST / {"jsonrpc":"2.0","id":3,"method":"eth_gasPrice","params":[]}
<-- {"jsonrpc":"2.0","result":"0x2e90edd000","id":3}

Options

$ http-json-proxy
Start a HTTP JSON proxy server.

Options:
  --version     Show version number                                    [boolean]
  --port, -p    the port the server should listen to                    [number]
  --target, -t  the proxied API server URL                   [string] [required]
  --help        Show help                                              [boolean]

API

The module can also be used programmatically as follows:

const createProxy = require('http-json-proxy')

const options = {
  port: 18545,
  target: 'http://localhost:8545',
  onReq: function (req) {
    console.log('-->', req.method, req.url, JSON.stringify(req.body))
    return req
  },
  onRes: function (body) {
    console.log('<--', JSON.stringify(body))
    return body
  }
}

const proxy = createProxy(options)

createProxy(options)

Creates a new proxy that starts listening on the specified port, forwarding all requests to the target server. It returns an http.Server instance.

options.port

Is the port the proxy will listen on. If not specified, the proxy will start listening to a random unused port.

options.host

Is the host the proxy will listen on. If not specified, the proxy will listen in all interfaces.

options.target

Is the proxied API server URL.

options.onReq

Will be called on each request with the req object that will be forwarded to the target server and shall return that req. Any of the properties of the req object can be altered to modify the actual request that is sent to the target server. Defaults to the identity function.

options.onRes

Will be called on each response with the body of the response and shall return the actual body to be provided to the client. It can be altered to provide a different response too. Defaults to the identity function.

options.onErr

Will be called on each request error with the corresponding err object and shall return the same, altered or different err object that will be returned to the client along with a 500 status code. Defaults to the identity function.

License

MIT