GithubHelp home page GithubHelp logo

devdoshi / apihero Goto Github PK

View Code? Open in Web Editor NEW

This project forked from triggerdotdev/apihero

0.0 0.0 0.0 4.25 MB

Make every API you use faster and more reliable with one line of code ⚡️

Home Page: https://apihero.run

License: Apache License 2.0

Shell 0.09% JavaScript 2.27% TypeScript 95.57% CSS 1.46% Dockerfile 0.61%

apihero's Introduction

API Hero

Make every API you use faster and more reliable with one line of code.

  • Monitor every single API call your app makes
  • Get alerts when issues arise and debug them easily
  • Automatically cache responses using standard HTTP caching semantics
  • Override HTTP caching semantics and cache more aggressively
  • Get alerts BEFORE you hit rate limits
  • Automatically obfuscate sensitive data
  • All with just one line of code

You can self-host or use the hosted version.

Installation

We currently only support JavaScript & TypeScript, but more platforms are coming soon.

Install the latest apihero-js package:

npm install apihero-js@latest

If you only plan on using API Hero in development or testing environments, install into your devDependencies:

npm install apihero-js@latest --save-dev

Usage

To start intercepting API requests and proxying them through the API Hero service, you first will need a Project Key which you can receive by signing up to apihero.run.

If you are running a Node.js app, include the following code somewhere that will be run at initialization:

import { setupProxy } from "apihero-js/node";

const proxy = setupProxy({ projectKey: "<PROJECT_KEY_HERE>" });

// Start intercepting requests and sending them to proxy.apihero.run
proxy.start();

setupProxy works by intercepting requests at the node:http and node:https level, and modifies the requests before they are sent to the API Hero proxy server. We take the same approach as Mock Service Worker (and we actually leverage their low-level HTTP/HTTPS request interception library)

By default, this will proxy all requests, which may not be what you want (and could be a possible security issue). You can whitelist certain origins using the allow option:

const proxy = setupProxy({
  projectKey: "<PROJECT_KEY_HERE>",
  allow: ["api.github.com/*"],
});

You can also use a blocklist approach using the deny option:

const proxy = setupProxy({
  projectKey: "hero_123abc",
  deny: ["internal.api.dev/*"],
});

If you don't want to intercept requests in production, you can do something like this:

if (process.env.NODE_ENV !== "production") {
  const { setupProxy } = require("apihero-js/node");
  const proxy = setupProxy({
    projectKey: "hero_123abc",
  });
  proxy.start();
}

You can also selectively stop intercepting/proxying requests using proxy.stop();

Coming soon

We plan on adding browser support very soon, as well as a custom fetch module that will allow you to use API Hero without stubbing the Node.js request modules.

Self hosting

A detailed self-hosting guide is coming soon. For now you can use the Readmes for the separate apps.

Plans

API Hero is still in early developer preview, and we plan on adding more features and platforms as quickly as we can. If you have any questions or feedback, please reach out to me personally: [email protected].

apihero's People

Contributors

d-k-p avatar ericallam avatar matt-aitken avatar samejr avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.