https://github.com/dakdevs/rest-api-proxy
https://github.com/dakdevs/rest-api-proxy
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/dakdevs/rest-api-proxy
- Owner: dakdevs
- Created: 2019-07-03T18:13:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T03:36:21.000Z (about 3 years ago)
- Last Synced: 2025-02-15T05:25:06.778Z (11 months ago)
- Language: JavaScript
- Size: 903 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rest API Proxy
This package allows you to proxy a rest API. For use in API routers to create routes that proxy to the given API.
# Installation
```bash
yarn add rest-api-proxy
```
# Usage
```js
import express from 'express';
import restApiProxy from 'rest-api-proxy';
const app = express();
app.all('/proxy/twitter/:path*', async (req, res) => {
const proxy = restApiProxy({
host: 'https://api.twitter.com/v1',
headers: {
'X-Auth-Token': 'XXXXXXX',
},
});
const requestData = req.body || undefined;
const response = await proxy(req.method, req.param.path, {
data: requestData,
query: req.query,
headers: req.headers,
});
return res.status(response.statusCode).set(response.headers).send(response.body);
});
app.listen(4000, () => {
console.log('Server running...');
});
```