0.0.8 • Published 6 months ago

api-proxy-pro v0.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

backend-proxy

CircleCI npm version npm

Backend proxy is a tool to route your REST API through a proxy

Install

$ npm i -g backend-proxy

Usage

$ backend-proxy --url PROXY_URL --token-name --token TOKEN --use-headers --port 3000 --read-only

Options

OptionInputDefaultRequired
--portPort on which proxy will serve requests3000
--urlUrl to proxy toN/A*
--secureListen over https instead of http. Will use a test self signed certificatefalse
--token-nameName of the token query parameter / header name used to pass tokentoken
--tokenToken to use for requestsN/A
--use-headersPass token as a http header instead of a url query stringfalse
--read-onlyOnly allow GET requestsfalse
--rewriteTransforms paths from when proxying request*
--debugPrint extra information for debuggingfalse
--securePrint extra information for debuggingfalse

Usecases

  • Proxies cookies properly by removing the scoped domain
  • Adds proper CORs headers allowing full access from the browser
  • Supports POST requests and proxies them transparently
  • Read Only mode allows easy testing for backend APIs where accidental changes are prevented

Example

$ backend-proxy --url https://reqres.in/api

Then

GET http://localhost:3000/users/2

proxies to

GET https://reqres.in/api/users/2

Path Rewrites

--rewrite option can be used multiple times to transform many paths like so:

$ backend-proxy --url https://reqres.in/api --rewrite "/users -> /clients" --rewrite "/customers -> /clients"

Then

GET http://localhost:3000/users/2
GET http://localhost:3000/customers/4

proxies to

GET https://reqres.in/api/clients/2
GET https://reqres.in/api/clients/4

URL mappings

--map option can be used to select a url if multiple urls are given. This can be used in scenarios where multiple paths map to different urls.

$ backend-proxy --url http://url_1.com --url http://url_2.com --map "/users -> 0" --map "/posts -> 1"

In above example, /users/25 will proxy to http://url_1.com/users/25 where as /posts/22 will proxy to http://url_2.com/posts/22 Note that url that comes first gets precedence. Either the first mapping matched will be used, or fall back to first url given. The mapped number is an index, and starts from 0 not 1

License

Licensed under the MIT License

View this on npm

Made with ❤ by Rikin Katyal

0.0.8

6 months ago

0.0.6

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago