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

intervene

v4.0.0

Published

_Hassle free HTTP(S) API proxying for development_

Downloads

30

Readme

Intervene npm version build status

Hassle free HTTP(S) API proxying for development

Quickly mock endpoints in HTTP(S) APIs, edit requests and responses, proxy everything else to the real API.

https://intervene.dev

Example

Let's say you've got a website that accesses your API at https://mycompany.com/api. There's a GET /api/cat that returns some JSON information (name, color, image) about a cat. You're planning a major update in the backend to add GET /api/dog. It's going to take the backend developers a few days to get that implemented, but you want to start work on the frontend already.

Run this on the command line (Mac or Linux)

intervene create https://mycompany.com

It's going to ask for admin privileges because it needs to override some things. It creates a file called mycompany.com.ts, which is an intervene config. Leave the process running and open the file.

import { ProxyConfig, routeBuilder } from '/Users/foo/Library/node_modules/intervene';

const config: ProxyConfig = {
  target: 'https://mycompany.com',

  routes: {

    // Some example configurations follow
    // ...

  }
};

export default config;

(Don't worry about path in the import statement. It's going to depend on how you installed intervene, but it is smart enough to automatically patch the path at runtime when importing the config)

You should see the site still works as normal (in chrome at least, you'll get a certificate warning in Firefox which you'll need to accept). GET /api/cat still responds the same.

Now let's change the configuration to include a new route:


const config: ProxyConfig = {
  target: 'https://mycompany.com',

  routes: {

    '/api/dog': {
      name: 'Fido',
      color: 'Beige',
      image: 'https://dogimages.com/bestdog.jpg'
    }

  }
};

Save the file (no need to restart the intervene process, it will notice and restart itself.

Now, if you curl -k https://mycompany.com/api/dog, you'll get the JSON specified in the file. curl -k https://mycompany.com/api/cat still responds the same, because it proxies through to the real https://mycompany.com.

Altering responses

Another update is planned to also return the age of the cat. You don't want to mock the whole endpoint, you just want to add the age property to whatever the real backend returns.

Let's make a method endpoint.


const config: ProxyConfig = {
  target: 'https://mycompany.com',

  routes: {

    '/api/dog': {
      name: 'Fido',
      color: 'Beige',
      image: 'https://dogimages.com/bestdog.jpg'
    },

    '/api/cat': async (req, h, proxy) => {
      const response = await proxy();
      response.body.age = 7;
      return response;
    }

  }
};

Save the file again, and the https://mycompany.com/api/cat endpoint now has an added age property, with the rest of the response exactly as returned by the real server.

Documentation

See the documentation at https://intervene.dev