https://github.com/imjuni/jin-axios-curlize
AxiosRequestConfig to curl command
https://github.com/imjuni/jin-axios-curlize
Last synced: about 1 year ago
JSON representation
AxiosRequestConfig to curl command
- Host: GitHub
- URL: https://github.com/imjuni/jin-axios-curlize
- Owner: imjuni
- License: mit
- Created: 2023-06-25T22:44:23.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-11-15T00:18:21.000Z (over 2 years ago)
- Last Synced: 2024-05-01T20:46:43.115Z (about 2 years ago)
- Language: TypeScript
- Size: 476 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jin-axios-curlize

[](https://npmcharts.com/compare/jin-axios-curlize?minimal=true)
[](https://github.com/imjuni/jin-axios-curlize)
[](https://github.com/imjuni/jin-axios-curlize/issues)
[](https://www.npmjs.com/package/jin-axios-curlize)
[](https://github.com/imjuni/jin-axios-curlize/blob/master/LICENSE)
[](https://github.com/imjuni/jin-axios-curlize/actions/workflows/ci.yml)
[](https://codecov.io/gh/imjuni/jin-axios-curlize)
[](https://github.com/prettier/prettier)
jin-axios-curlize create curl command from AxiosRequestConfig.
Why?
1. automatic create curl command from AxiosRequestConfig
1. Quickly repeat error request
1. Support querystring, header, body replacer
1. work without intercepter, no need to request execute for curl command creation
## Table of Contents
- [installation](#installation)
- [How to works?](#how-to-works)
- [Usage](#usage)
- [Options](#options)
- [How do I add transaction id on querystring?](#how-do-i-add-transaction-id-on-querystring)
- [jin-curlize](#jin-curlize)
## installation
```bash
npm install jin-axios-curlize --save-dev
```
## How to works?
`jin-axios-curlize` create curl command from `AxiosRequestConfig`. For example,
- `AxiosRequestConfig`.`headers` to `--header` option
- `AxiosRequestConfig`.url and `AxiosRequestConfig`.params to querystring and href
```mermaid
flowchart LR
IMH[AxiosRequestConfig] --> JC[jin-axios-curlize]
JC --> C[curl command]
```
## Usage
```ts
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"}'
```
## Options
| 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 |
## How do I add transaction id on querystring?
```ts
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);
},
},
});
```
## jin-curlize
If you want that curl command generate from FastifyRequest, use [jin-curlize](https://www.npmjs.com/package/jin-curlize) package.