1.3.0 • Published 6 months ago

jin-axios-curlize v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

jin-axios-curlize

ts Download Status Github Star Github Issues NPM version License ci codecov code style: prettier

jin-axios-curlize create curl command from AxiosRequestConfig.

Why?

  1. automatic create curl command from AxiosRequestConfig
  2. Quickly repeat error request
  3. Support querystring, header, body replacer
  4. work without intercepter, no need to request execute for curl command creation

Table of Contents

installation

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
flowchart LR
    IMH[AxiosRequestConfig] --> JC[jin-axios-curlize]
    JC --> C[curl command]

Usage

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

NameRequirementDescription
prettifyrequireApply prettifing. Add newline and backslash add on line-ending
indentoptionalOnly work on prettify set true, make space size
disableFollowRedirectoptionalIf set true, remove --location option from command
replacer.querystringoptionalreplacer for querystring
replacer.bodyoptionalreplacer for body
replacer.headeroptionalreplacer for header

How do I add transaction id on querystring?

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 package.

1.2.0

6 months ago

1.3.0

6 months ago

1.1.0

10 months ago

1.0.0

11 months ago

0.8.0

11 months ago