jin-axios-curlize create curl command from AxiosRequestConfig.
Why?
- automatic create curl command from AxiosRequestConfig
- Quickly repeat error request
- Support querystring, header, body replacer
- work without intercepter, no need to request execute for curl command creation
npm install jin-axios-curlize --save-dev
jin-axios-curlize
create curl command from AxiosRequestConfig
. For example,
AxiosRequestConfig
.headers
to--header
optionAxiosRequestConfig
.url andAxiosRequestConfig
.params to querystring and href
flowchart LR
IMH[AxiosRequestConfig] --> JC[jin-axios-curlize]
JC --> C[curl command]
import axios, { AxiosRequestConfig } from 'axios';
import { createFromAxios } from 'jin-axios-curlize';
const req: AxiosRequestConfig = {
url: 'http://localhost:3000/v1/superhero/i-am-unique-id'
method: 'put',
data: {
name: 'ironman'
}
}
const reply = await axios.request(req);
console.log('curl command: ', createFromAxios(req));
// curl -X PUT 'http://localhost:3000/v1/superhero/i-am-unique-id' -d $'{"name":"ironman"}'
Name | Requirement | Description |
---|---|---|
prettify | require | Apply prettifing. Add newline and backslash add on line-ending |
indent | optional | Only work on prettify set true, make space size |
disableFollowRedirect | optional | If set true, remove --location option from command |
replacer.querystring | optional | replacer for querystring |
replacer.body | optional | replacer for body |
replacer.header | optional | replacer for header |
import { createV3, encodeQuerystring } from 'jin-curlize';
createV3(req, {
prettify: false,
replacer: {
querystring: (qs) => {
const next = new URLSearchParams(qs);
// add your transaction id on querystring, `uuidgen` is linux or macosx uuid generator command
next.set('tid', `'"$(uuidgen)"'`);
return encodeQuerystring(next);
},
},
});
If you want that curl command generate from FastifyRequest, use jin-curlize package.