Package Exports
- run-api
- run-api/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (run-api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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: devarif.me@gmail.com