All Projects → uyu423 → r2curl

uyu423 / r2curl

Licence: MIT license
Node.js Request Wrapper (axios, fetch, ..) to cURL Command String

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to r2curl

axios-curlirize
axios plugin converting requests to cURL commands, saving and logging them.
Stars: ✭ 152 (+406.67%)
Mutual labels:  curl, axios
go-axios
HTTP Request package for golang.
Stars: ✭ 29 (-3.33%)
Mutual labels:  curl, axios
rocketshoes-react-native
NetShoes Clone with React Native and Redux
Stars: ✭ 38 (+26.67%)
Mutual labels:  axios
fastify-axios
Add axios http client to your fastify instance
Stars: ✭ 28 (-6.67%)
Mutual labels:  axios
vue-webpack-boilerplate
A webpack boilerplate with vue-loader, axios, vue-router and vuex
Stars: ✭ 51 (+70%)
Mutual labels:  axios
textics
📉 JavaScript Text Statistics that counts lines, words, chars, and spaces.
Stars: ✭ 36 (+20%)
Mutual labels:  curl
easyhttp
EasyHttp 是一个轻量级、语义化、对IDE友好的HTTP客户端,支持常见的HTTP请求、异步请求和并发请求,让你可以快速地使用 HTTP 请求与其他 Web 应用进行通信。
Stars: ✭ 31 (+3.33%)
Mutual labels:  curl
boast
I want track all HTTP requests, and replay it easily.
Stars: ✭ 61 (+103.33%)
Mutual labels:  curl
pg curl
PostgreSQL curl allows most curl actions, including data transfer with URL syntax via HTTP, HTTPS, FTP, FTPS, GOPHER, TFTP, SCP, SFTP, SMB, TELNET, DICT, LDAP, LDAPS, FILE, IMAP, SMTP, POP3, RTSP and RTMP
Stars: ✭ 30 (+0%)
Mutual labels:  curl
1c http
Подсистема 1С для работы с HTTP
Stars: ✭ 48 (+60%)
Mutual labels:  curl
guile-curl
A language binding for the CURL network client library for the Guile version of the Scheme language
Stars: ✭ 23 (-23.33%)
Mutual labels:  curl
miniprogram-network
Redefine the Network API of Wechat MiniProgram (小程序网络库)
Stars: ✭ 93 (+210%)
Mutual labels:  axios
fortran-curl
Fortran 2008 interface bindings to libcurl
Stars: ✭ 25 (-16.67%)
Mutual labels:  curl
NeteaseCloudWebApp
This is a vue for NeteaseCloud projects!
Stars: ✭ 2,512 (+8273.33%)
Mutual labels:  axios
vue-admin-webapp
基于vuejs+element-ui 后台管理系统
Stars: ✭ 62 (+106.67%)
Mutual labels:  axios
Speedport-Plus-Cosmote-Router-hacks
Exploring the Sercomm made router of Cosmote - OTE Group (Deutsche Telekom in Greece)
Stars: ✭ 64 (+113.33%)
Mutual labels:  curl
Vue2.x-mobileSystem
基于Vue2.0的移动端项目,项目没有使用vue-cli,全部手写,让小白更容易学习理解
Stars: ✭ 72 (+140%)
Mutual labels:  axios
use-axios-hooks
axios hooks for common network calls scenarios
Stars: ✭ 27 (-10%)
Mutual labels:  axios
Vue-CAMP
VueJS
Stars: ✭ 16 (-46.67%)
Mutual labels:  axios
redux-rest-adapter
REST adapter for redux
Stars: ✭ 13 (-56.67%)
Mutual labels:  axios

r2curl

npm version Download Status Github Star MIT Licence CircleCI Codacy Badge Code Climate Test Coverage

Background

  • r2curl was inspired by @delirius325/axios-curlirize.
  • axios-curlirize is very convenient. but works as a middleware for axios, and I think this part is black box logic
    • it contains potentially asynchronous concurrency issues and difficult-to-manage elements.
  • So I created a new 'Request to cURL' package that is completely independent of the dependencies of axios.

Feature

  • Generates cURL commands completely independently from the outside of the request wrapper package.
  • Provides additional options involved in generating the cURL command.
  • It will be updated soon to be available in packages like node-fetch or request.

Roadmap

Install

npm install r2curl --save

Usage

axios

AxiosResponse

// if js, const r2curl = require('r2curl');
import r2curl from 'r2curl';

const response = await axios.get('https://google.com');
const curl = r2curl(response);

console.log(curl);
// stdout "curl -X GET 'https://google.com' -H 'Accept:application/json, text/plain, */*' -H 'User-Agent:axios/0.18.0'"

AxiosRequestConfig

// if js, const r2curl = require('r2curl');
import r2curl from 'r2curl';

// config as AxiosRequestConfig
const config = {
  url: 'https://google.com',
  method: 'POST',
  data: {
    caller: 'curl tester',
  },
  headers: {
    'Content-Type': 'application/json',
  },
};

const curl = r2curl(reqeustConfig);
console.log(curl);
// stdout `curl -X POST 'https://google.com' -H 'Content-Type:application/json' --data '{"caller":"curl tester"}'`

const response = await axios.request(config);

node-fetch

request

More r2curl Options

option.quote

  • Determines the type of quota around the body and uri.
  • default is single
import r2curl from 'r2curl';

// option as IR2CurlOptions.ts
const option = {
  /** Determines the type of quota around the body and uri. */
  quote: 'double',
};

const curl = r2curl(requestConfig, option);
console.log(curl); 

option.defaultContentType

  • Determines the default Content-Type header value for POST and PUT requests.
  • default is application/json; charset=utf-8
  • Type is (enum) HTTP_HEADER_CONTENT_TYPE | string | false;
  • If you give (boolean) false to defaultContentType, you can disable Content-Type Header.
import r2curl, { HTTP_HEADER_CONTENT_TYPE } from 'r2curl';

// const optionUsingEnum = {
//   defaultContentType: HTTP_HEADER_CONTENT_TYPE.TEXT,
// };
const option = {
  defaultContentType: 'application/json5',
}
const request: AxiosRequestConfig = { url: 'https://google.com', method: 'POST' };

const curl = r2curl(config, option);
console.log(curl); 
// output: curl -X POST 'https://google.com' -H 'Content-Type:application/json5

option.forceBody

  • Accept Body all HTTP Method.
  • By default, Body is not allowed in GET and DELETE methods.
  • However, some services such as ElasticSearch should be able to use the Body as a GET method. At this point, use this option to activate the Body.
import r2curl from 'r2curl';

const config: AxiosRequestConfig = {
  url: 'https://google.com',
  method: 'GET',
  data: {
    caller: 'https://github.com/uyu423/r2curl',
    sorry: true,
  },
};

const option = {
  forceBody: true,
}

const curl = r2curl(config, option);
// output: 'curl -X GET \'https://google.com\' --data \'{"caller":"https://github.com/uyu423/r2curl","sorry":true}\''
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].