Gathering detailed insights and metrics for dk-request
Gathering detailed insights and metrics for dk-request
npm install dk-request
Typescript
Module System
Node Version
NPM Version
69.5
Supply Chain
97.7
Quality
85.5
Maintenance
50
Vulnerability
99.6
License
TypeScript (92.68%)
JavaScript (4.68%)
HTML (1.67%)
CSS (0.75%)
SCSS (0.19%)
Shell (0.02%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
13,026
Last Day
4
Last Week
17
Last Month
318
Last Year
5,031
20 Stars
243 Commits
3 Forks
3 Watchers
1 Branches
1 Contributors
Updated on Feb 10, 2025
Minified
Minified + Gzipped
Latest Version
3.4.10
Package Id
dk-request@3.4.10
Unpacked Size
32.03 kB
Size
8.00 kB
File Count
29
NPM Version
lerna/8.1.2/node@v22.7.0+x64 (linux)
Node Version
22.7.0
Published on
Dec 03, 2024
Cumulative downloads
Total Downloads
Last Day
0%
4
Compared to previous day
Last Week
-75.7%
17
Compared to previous week
Last Month
-8.6%
318
Compared to previous month
Last Year
-23.4%
5,031
Compared to previous year
2
1
3
[!WARNING]
It's fine if you use this library from NPM package with a static versioning in case you want it for some pet-project or to test it's capabilities.But for production use it's strongly recommended to create a fork, because I do not write Changelogs and may break / add some functionality without notice.
ts-interface-checker
. Checkers could be created using
dk-file-generatorblob
with customizable file nameurl
as functionomit_
are used in in url
creation but omitted in bodyAdd dk-request
to package.json and install.
1import { AxiosError } from 'axios'; 2import { request, errors } from 'dk-request'; 3 4type TypeRequest = { 5 id: string; 6} 7 8type TypeResponse = { 9 data: string; 10} 11 12// possibly auto-generated 13const validators = t.createCheckers({ 14 TypeRequest: t.iface([], { id: 'string' }), 15 TypeResponse: t.iface([], { data: 'string' }), 16}); 17 18request({ 19 url: 'https://google.com/api/get-items', 20 // url: (requestParams) => `https://google.com/api/get-items/${requestParams.id}`, 21 apiName: 'getItems', 22 requestParams: { id: 'id' } as TypeRequest, 23 validatorRequest: validators.TypeRequest, 24 validatorResponse: validators.TypeResponse, 25}).then((response: TypeResponse) => { 26 // response is validated and cleared, put it in store or use as you need 27 28 successHandler(response); 29}).catch((error: Error | AxiosError) => { 30 // if it's validation error then 31 // error.name === errors.VALIDATION 32 // error.message smth. like 33 // 'validateRequest: request.id is missing for "getItems"' 34 // 'validateResponse: response.data is not a string for "getItems"' 35 36 errorHandler(error); 37});
url
- string | ((request: any) => string)
- full url
apiName
- string
- just for logging
requestParams
- Record<string, any> & { formData?: any; downloadAsFile?: boolean }
If you need to send FormData include it in formData
. Other params will not be sent, but
could still be used in url
function.
If you need to download file passed as blob
by backend use downloadAsFile: true
, this
way response validation will be omitted.
mock
(optional) - TypeResponse
, there will be no actual request to API, but validations are
applied
method
(optional, default POST
) - 'GET' | 'POST' | 'PUT' | 'DELETE'
headers
(optional) - Record<string, any>
extraneousLogger
(optional) - logger for dk-checker-remove-extraneous
validatorRequest
(optional) - Checker
validatorResponse
(optional) - Checker
disableCredentials
(optional) - boolean
- restrict or allow sending of cookies along with request
omitResponseValidation
(optional) - boolean
- restrict or allow response validation
afterRequestInterceptor
(optional) - (response: AxiosResponse) => Promise<void>
- a method for
performing some manipulations with response, like checking response.headers
(ex. server sends
JWT token in headers)
1afterRequestInterceptor: (axiosResponse) => { 2 const newToken = axiosResponse.headers.authorization; 3 4 if (newToken) setTokenToStore(newToken); 5 6 return Promise.resolve(); 7}
downloadFileNameGetter
(optional) - (response: AxiosResponse) => string
- a method for
defining custom downloaded file name, ex.
1downloadFileNameGetter: (axiosResponse) => { 2 return ( 3 axiosResponse.headers['content-disposition']?.split('filename=')?.[1]?.replaceAll('"', '') || 4 'result.csv' 5 ); 6}
For access to response headers like
content-disposition
don't forgetexpose-headers
header in server response
No vulnerabilities found.
No security vulnerabilities found.