Installations
npm install easy-fetch-api
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
16.17.0
NPM Version
8.15.0
Score
71.9
Supply Chain
98.9
Quality
75.9
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
raulrene
Download Statistics
Total Downloads
14,570
Last Day
3
Last Week
39
Last Month
127
Last Year
2,706
GitHub Statistics
2 Stars
59 Commits
1 Forks
2 Watching
17 Branches
1 Contributors
Bundle Size
7.31 kB
Minified
1.66 kB
Minified + Gzipped
Package Meta Information
Latest Version
2.7.1
Package Id
easy-fetch-api@2.7.1
Unpacked Size
31.09 kB
Size
6.18 kB
File Count
7
NPM Version
8.15.0
Node Version
16.17.0
Publised On
15 May 2023
Total Downloads
Cumulative downloads
Total Downloads
14,570
Last day
50%
3
Compared to previous day
Last week
30%
39
Compared to previous week
Last month
3.3%
127
Compared to previous month
Last year
-5.4%
2,706
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
(easy) Fetch API
Easy to use and lightweight wrapper for the Fetch API.
- Provides CRUD methods
- Each method returns a Promise, therefore works with async/await
- Automatically sets required headers (for POST, PUT and PATCH it sets
Accept
andContent-Type
headers toapplication/json
) - Provides method for easily posting form data
- Pre-request and post-request callbacks for an easier integration with store-based architectures like Redux - see example
This library does not provide a polyfill for the Fetch API.
Installation
1npm install --save easy-fetch-api
Usage
1import Api, { RESPONSE_TYPES } from 'easy-fetch-api'; 2 3Api.get({ url: '/api/me', callback: console.log }); 4 5await Api.post({ url: '/api/register', data: { email: 'value', password: 'value' } }); 6 7// Set headers on each request 8Api.get({ url: '/api/me', headers: { Authorization: 'Bearer token' } }); 9 10// Or set headers globally and they are automatically passed on each request 11Api.setHeaders({ Authorization: 'Bearer token' }); 12 13console.log(RESPONSE_TYPES) // { json: 'json', blob: 'blob', text: 'text' }
More detailed usage examples below in the docs of each method:
SET BASE URL
Set a base URL (if needed).
This will be used to prefix all later URLs
1Api.setBaseUrl('https://api-domain.com');
GET
Performs a HTTP Get request.
1Api.get({ 2 url: '/api/get', 3 headers: { Authorization: 'token' }, 4 query: { q1: 'value', qn: 'value' }, 5 responseType: Api.RESPONSE_TYPES.blob, 6 callback: () => {} 7)};
- url (String, required) - URL to make request to
- headers (Object, optional) HTTP Headers object in the form of
{ headerKey: headerValue }
- query (Object, optional) Query object in the form of
{ queryKey: queryValue }
- callback (Function, optional) Function called after the server responds, with resulting data
- responseType (String, optional) one of the RESPONSE_TYPES allowed values
- returns Promise
POST (json)
Performs a HTTP Post request.
1Api.post({ 2 url: '/api/post', 3 data: { email: 'value', password: 'value' }, 4 headers: { Authorization: 'token' }, 5 callback: () => {} 6)};
- url (String, required) - URL to make request to
- data (Object, required) - Object body to be posted
- headers (Object, optional) HTTP Headers object in the form of
{ headerKey: headerValue }
. Note that there are two preset heders:{ Accept: 'application/json', 'Content-Type': 'application/json' }
. You can override them using this parameter - callback (Function, optional) Function called after the server responds, with resulting data
- responseType (String, optional) one of the RESPONSE_TYPES allowed values
- returns Promise
POST FORM
Performs a HTTP Post request with form data.
1Api.postForm({ 2 url: '/api/postForm', 3 data: 'email=value&password=value', 4 headers: { Authorization: 'token' }, 5 callback: () => {} 6)};
- url (String, required) - URL to make request to
- data (String, required) - Form data to be posted
- headers (Object, optional) HTTP Headers object in the form of
{ headerKey: headerValue }
. Note that there are two preset heders:{ Accept: 'application/json', 'Content-Type': 'application/json' }
. You can override them using this parameter - callback (Function, optional) Function called after the server responds, with resulting data
- returns Promise
PUT
Performs a HTTP Put request.
1Api.put({ 2 url: `/api/put/${id}`, 3 data: { email: 'value', password: 'value' }, 4 headers: { Authorization: 'token' }, 5 callback: () => {} 6)};
- url (String, required) - URL to make request to
- data (Object, required) - Object body to be updated
- headers (Object, optional) HTTP Headers object in the form of
{ headerKey: headerValue }
. Note that there are two preset heders:{ Accept: 'application/json', 'Content-Type': 'application/json' }
. You can override them using this parameter - callback (Function, optional) Function called after the server responds, with resulting data
- responseType (String, optional) one of the RESPONSE_TYPES allowed values
- returns Promise
PATCH
Performs a HTTP Patch request.
1Api.patch({ 2 url: `/api/put/${id}`, 3 data: { email: 'value', password: 'value' }, 4 headers: { Authorization: 'token' }, 5 callback: () => {} 6)};
- url (String, required) - URL to make request to
- data (Object, required) - Object body to be updated
- headers (Object, optional) HTTP Headers object in the form of
{ headerKey: headerValue }
. Note that there are two preset heders:{ Accept: 'application/json', 'Content-Type': 'application/json' }
. You can override them using this parameter - callback (Function, optional) Function called after the server responds, with resulting data
- responseType (String, optional) one of the RESPONSE_TYPES allowed values
- returns Promise
DELETE
Performs a HTTP Delete request.
1Api.delete({ 2 url: '/api/delete', 3 headers: { Authorization: 'token' }, 4 query: { q1: 'value', qn: 'value' }, 5 callback: () => {} 6)};
- url (String, required) - URL to make request to
- headers (Object, optional) HTTP Headers object in the form of
{ headerKey: headerValue }
- query (Object, optional) Query object in the form of
{ queryKey: queryValue }
- callback (Function, optional) Function called after the server responds, with resulting data
- returns Promise
CallBefore and Callback
Functions to be called before the request is fired and after the server responds, respectively. Facilitates integration with store-based architectures like Redux.
1Api.get({ 2 url: '/api/get', 3 callBefore: () => { dispatch({ type: ACTIONS.LOADING }) }, 4 callback: result => { dispatch({ type: ACTIONS.LOADING_DONE, data: result }) } 5)};
Licence
The code is open-source and available under the MIT Licence. More details in the LICENCE.md file.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/21 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 9 are checked with a SAST tool
Reason
56 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-c6rq-rjc2-86v2
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-phwq-j96m-2c2q
- Warn: Project is vulnerable to: GHSA-ghr5-ch3p-vcr6
- Warn: Project is vulnerable to: GHSA-r9p9-mrjm-926w
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3
- Warn: Project is vulnerable to: MAL-2023-462
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-h9rv-jmmf-4pgx
- Warn: Project is vulnerable to: GHSA-hxcc-f52p-wc94
- Warn: Project is vulnerable to: GHSA-4g88-fppr-53pp
- Warn: Project is vulnerable to: GHSA-4jqc-8m5r-9rpr
- Warn: Project is vulnerable to: GHSA-4rq4-32rv-6wp6
- Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj
- Warn: Project is vulnerable to: GHSA-vx3p-948g-6vhq
- Warn: Project is vulnerable to: GHSA-j44m-qm6p-hp7m
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw
- Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-cf4h-3jhx-xvhq
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
1.7
/10
Last Scanned on 2025-01-20
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to easy-fetch-api
fetch-sse
An easy API for making Event Source requests, with all the features of fetch(), Supports browsers and node.
fetch-wordpress-api
Easy fetching from the Wordpress API
@umijs/fetch-sse
An easy API for making Event Source requests, with all the features of fetch(), Supports browsers and nodejs.
@ambassify/fetch-api
Small class to create easy to use API clients with fetch