run-api
v0.1.0
Published
npm package to resolve CORS problem
Downloads
1
Readme
run-api
A npm package to resolve CORS problem. You can use this package to run your API locally and test it with your frontend. It will not show any error related to CORS.
It's a beta version, so it may have some bugs. If you find any bug, please create an issue or contact with me.
npm package url
https://www.npmjs.com/package/run-api
Installation
npm i run-api
# or
yarn add run-api
Usage
GET
// ES5 const runApi = require('run-api'); // This is optional. If you don't pass data, it will be empty object. const options = { headers: { "Content-Type": "application/json", }, }; runApi.get('http://localhost:3000/blog', options) .then(res => console.log(res)) .catch(err => console.log(err));
// ES6 import runApi from 'run-api'; // This is optional. If you don't pass data, it will be empty object. const options = { headers: { "Content-Type": "application/json", }, }; try { const res = await runApi.get('http://localhost:3000/blog', options); console.log(res); } catch (err) { console.log(err); }
POST
// ES5 const runApi = require('run-api'); const reqData = { title, desc }; // This is optional. If you don't pass data, it will be empty object. const options = { headers: { "Content-Type": "application/json", }, }; runApi.post('http://localhost:3000/blog', reqData, options) .then(res => console.log(res)) .catch(err => console.log(err));
// ES6 import runApi from 'run-api'; const reqData = { title, desc }; // This is optional. If you don't pass data, it will be empty object. const options = { headers: { "Content-Type": "application/json", }, }; try { const res = await runApi.post('http://localhost:3000/blog', reqData, options); console.log(res); } catch (err) { console.log(err); }
PUT
// ES5 const runApi = require('run-api'); const reqData = { title, desc }; // This is optional. If you don't pass data, it will be empty object. const options = { headers: { "Content-Type": "application/json", }, }; runApi.put('http://localhost:3000/blog/1', reqData, options) .then(res => console.log(res)) .catch(err => console.log(err));
// ES6 import runApi from 'run-api'; const reqData = { title, desc }; // This is optional. If you don't pass data, it will be empty object. const options = { headers: { "Content-Type": "application/json", }, }; try { const res = await runApi.put('http://localhost:3000/blog/1', reqData, options); console.log(res); } catch (err) { console.log(err); }
PATCH
// ES5 const runApi = require('run-api'); const reqData = { title }; // This is optional. If you don't pass data, it will be empty object. const options = { headers: { "Content-Type": "application/json", }, }; runApi.patch('http://localhost:3000/blog/1', reqData, options) .then(res => console.log(res)) .catch(err => console.log(err));
// ES6 import runApi from 'run-api'; const reqData = { title }; // This is optional. If you don't pass data, it will be empty object. const options = { headers: { "Content-Type": "application/json", }, }; try { const res = await runApi.patch('http://localhost:3000/blog/1', reqData, options); console.log(res); } catch (err) { console.log(err); }
DELETE
// ES5 const runApi = require('run-api'); // This is optional. If you don't pass data, it will be empty object. const options = { headers: { "Content-Type": "application/json", }, }; runApi.delele('http://localhost:3000/blog/1', options) .then(res => console.log(res)) .catch(err => console.log(err));
// ES6 import runApi from 'run-api'; // This is optional. If you don't pass data, it will be empty object. const options = { headers: { "Content-Type": "application/json", }, }; try { const res = await runApi.delele('http://localhost:3000/blog/1', options); console.log(res); } catch (err) { console.log(err); }
Author
- Md Arif Hossain (@arifpro)
- Website: https://devarif.me
- LinkedIn: https://www.linkedin.com/in/devarif
- Email: [email protected]