All Projects → NickCarneiro → Curlconverter

NickCarneiro / Curlconverter

Licence: mit
convert curl commands to Python, JavaScript, Go, PHP, R, Dart, Java, MATLAB, Rust, Elixir and more

Programming Languages

javascript
184084 projects - #8 most used programming language
python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to Curlconverter

1c http
Подсистема 1С для работы с HTTP
Stars: ✭ 48 (-99.02%)
Mutual labels:  curl, code-generation
Pinocchio
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
Stars: ✭ 432 (-91.2%)
Mutual labels:  code-generation
Go Sword
【Go-sword】可视化CRUD管理后台生成工具
Stars: ✭ 364 (-92.58%)
Mutual labels:  code-generation
Awesome Roslyn
Curated list of awesome Roslyn books, tutorials, open-source projects, analyzers, code fixes, refactorings, and source generators
Stars: ✭ 395 (-91.95%)
Mutual labels:  code-generation
Loopy
A code generator for array-based code on CPUs and GPUs
Stars: ✭ 367 (-92.52%)
Mutual labels:  code-generation
Retool
Vendoring for executables written in Go
Stars: ✭ 403 (-91.79%)
Mutual labels:  code-generation
Curl For Win
Reproducible curl (and OpenSSL) binaries for Windows
Stars: ✭ 352 (-92.83%)
Mutual labels:  curl
Node Libcurl
libcurl bindings for Node.js
Stars: ✭ 447 (-90.89%)
Mutual labels:  curl
Gnorm
A database-first code generator for any language
Stars: ✭ 415 (-91.54%)
Mutual labels:  code-generation
Go Httpclient
Advanced HTTP client for golang
Stars: ✭ 390 (-92.05%)
Mutual labels:  curl
Swaggen
OpenAPI/Swagger 3.0 Parser and Swift code generator
Stars: ✭ 385 (-92.16%)
Mutual labels:  code-generation
Javaparser
Java 1-15 Parser and Abstract Syntax Tree for Java, including preview features to Java 13
Stars: ✭ 3,972 (-19.07%)
Mutual labels:  code-generation
Yii2 Httpclient
Yii 2 HTTP client
Stars: ✭ 406 (-91.73%)
Mutual labels:  curl
Ok.sh
A Bourne shell GitHub API client library focused on interfacing with shell scripts
Stars: ✭ 365 (-92.56%)
Mutual labels:  curl
Codemaker
A idea-plugin for Java/Scala, support custom code template.
Stars: ✭ 440 (-91.04%)
Mutual labels:  code-generation
Ocrserver
A simple OCR API server, seriously easy to be deployed by Docker, on Heroku as well
Stars: ✭ 359 (-92.69%)
Mutual labels:  curl
Mini C
Dr Strangehack, or: how to write a self-hosting C compiler in 10 hours
Stars: ✭ 372 (-92.42%)
Mutual labels:  code-generation
Kroto Plus
gRPC Kotlin Coroutines, Protobuf DSL, Scripting for Protoc
Stars: ✭ 400 (-91.85%)
Mutual labels:  code-generation
Goa
Design-based APIs and microservices in Go
Stars: ✭ 4,493 (-8.46%)
Mutual labels:  code-generation
Pi Timolo
Raspberry PI-TIMOLO ( PI-TImelapse, MOtion, LOwLight ) uses RPI picamera and OpenCV for Remote Headless Security Monitoring using Motion Tracking, Rclone Auto Sync files with remote storage services. Auto Twilight Transitions and Low Light Camera Settings. Panoramic images using PanTiltHat and More. This project is featured on GitHub Awesome software.
Stars: ✭ 441 (-91.01%)
Mutual labels:  curl

curlconverter

curlconverter transpiles curl commands into programs in other programming languages.

$ curlconverter --data "Hello, world!" example.com
import requests

data = 'Hello, world!'

response = requests.post('http://example.com', data=data)

You can choose the output language by passing --language <language>. The options are Python python (the default), JavaScript browser node node-request, Go go, Rust rust, PHP php, Java java, R r, Elixir elixir, Dart dart, MATLAB matlab and a few more.

NPM version

Live Demo

https://curl.trillworks.com

Install

Install the command line tool with

$ npm install --global curlconverter

Install the JavaScript library for use in your own projects with

$ npm install --save curlconverter

curlconverter requires Node 12+.

Usage

The JavaScript API is a bunch of functions that can take either a string of Bash code or an array

import * as curlconverter from 'curlconverter';

curlconverter.toPython("curl 'http://en.wikipedia.org/' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://www.wikipedia.org/' -H 'Cookie: GeoIP=US:Albuquerque:35.1241:-106.7675:v4; uls-previous-languages=%5B%22en%22%5D; mediaWiki.user.sessionId=VaHaeVW3m0ymvx9kacwshZIDkv8zgF9y; centralnotice_buckets_by_campaign=%7B%22C14_enUS_dsk_lw_FR%22%3A%7B%22val%22%3A%220%22%2C%22start%22%3A1412172000%2C%22end%22%3A1422576000%7D%2C%22C14_en5C_dec_dsk_FR%22%3A%7B%22val%22%3A3%2C%22start%22%3A1417514400%2C%22end%22%3A1425290400%7D%2C%22C14_en5C_bkup_dsk_FR%22%3A%7B%22val%22%3A1%2C%22start%22%3A1417428000%2C%22end%22%3A1425290400%7D%7D; centralnotice_bannercount_fr12=22; centralnotice_bannercount_fr12-wait=14' -H 'Connection: keep-alive' --compressed");
curlconverter.toPython(['curl', 'http://en.wikipedia.org/', '-H', 'Accept-Encoding: gzip, deflate, sdch', '-H', 'Accept-Language: en-US,en;q=0.8', '-H', 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36', '-H', 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', '-H', 'Referer: http://www.wikipedia.org/', '-H', 'Cookie: GeoIP=US:Albuquerque:35.1241:-106.7675:v4; uls-previous-languages=%5B%22en%22%5D; mediaWiki.user.sessionId=VaHaeVW3m0ymvx9kacwshZIDkv8zgF9y; centralnotice_buckets_by_campaign=%7B%22C14_enUS_dsk_lw_FR%22%3A%7B%22val%22%3A%220%22%2C%22start%22%3A1412172000%2C%22end%22%3A1422576000%7D%2C%22C14_en5C_dec_dsk_FR%22%3A%7B%22val%22%3A3%2C%22start%22%3A1417514400%2C%22end%22%3A1425290400%7D%2C%22C14_en5C_bkup_dsk_FR%22%3A%7B%22val%22%3A1%2C%22start%22%3A1417428000%2C%22end%22%3A1425290400%7D%7D; centralnotice_bannercount_fr12=22; centralnotice_bannercount_fr12-wait=14', '-H', 'Connection: keep-alive', '--compressed'])

and return a string of code like:

import requests

cookies = {
    'GeoIP': 'US:Albuquerque:35.1241:-106.7675:v4',
    'uls-previous-languages': '%5B%22en%22%5D',
    'mediaWiki.user.sessionId': 'VaHaeVW3m0ymvx9kacwshZIDkv8zgF9y',
    'centralnotice_buckets_by_campaign': '%7B%22C14_enUS_dsk_lw_FR%22%3A%7B%22val%22%3A%220%22%2C%22start%22%3A1412172000%2C%22end%22%3A1422576000%7D%2C%22C14_en5C_dec_dsk_FR%22%3A%7B%22val%22%3A3%2C%22start%22%3A1417514400%2C%22end%22%3A1425290400%7D%2C%22C14_en5C_bkup_dsk_FR%22%3A%7B%22val%22%3A1%2C%22start%22%3A1417428000%2C%22end%22%3A1425290400%7D%7D',
    'centralnotice_bannercount_fr12': '22',
    'centralnotice_bannercount_fr12-wait': '14',
}

headers = {
    'Accept-Encoding': 'gzip, deflate, sdch',
    'Accept-Language': 'en-US,en;q=0.8',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'Referer': 'http://www.wikipedia.org/',
    'Connection': 'keep-alive',
}

response = requests.get('http://en.wikipedia.org/', headers=headers, cookies=cookies)

Contributing

I'd rather write programs to write programs than write programs.

— Dick Sites, Digital Equipment Corporation, 1985

Make sure you're running Node 12 or greater. The test suite will fail on older versions of Node.js.

If you add a new generator, make sure to update the list of supported languages in bin/cli.js or else it won't be accessible from the command line. Further, you'll want to update test.js and index.js for your new generator to make it part of the testing.

If you want to add new functionality, start with a test.

  • Create a file containing the curl command in fixtures/curl_commands with a descriptive filename like post_with_headers.sh
  • Create a file containing the output in fixtures/python/ with a matching filename (but different extension) like post_with_headers.py
  • Run tests with npm test.
  • If your filenames match correctly, you should see one failing test. Fix it by modifying the parser in util.js or the generators in generators/

The parser generates a generic data structure consumed by code generator functions.

You can run a specific test with:

npm test -- test_name
# or
node test.js test_name

where test_name is a file (without the .sh extension) in fixtures/curl_commands/

You can run only the tests for a specific language generator with:

npm test -- --language=python
# or
node test.js --language=python

I recommend setting this up with a debugger so you can see exactly what the parser is passing to the generator. Here's my Intellij run configuration for a single test: Screenshot of intellij debug configuration

Before submitting a PR, please check that your JS code conforms to the code style enforced by StandardJS with

npm run lint

Use the following to fix your code if it doesn't:

npm run lint:fix

If you get stuck, please reach out via email. I am always willing to hop on a Google Hangout and pair program.

Contributors

  • jeayu (Java support)
  • Muhammad Reza Irvanda (python env vars)
  • Weslen Nascimento (Node fetch)
  • Roman Druzki (Backlog scrubbing, parsing improvements)
  • NoahCardoza (Command line interface)
  • ssi-anik (JSON support)
  • hrbrmstr (R support)
  • daniellockard (Go support)
  • eliask (improve python output)
  • trdarr (devops and code style)
  • nashe (fix PHP output)
  • bfontaine (reduce code duplication in test suite)
  • seadog007
  • nicktimko
  • wkalt
  • nico202
  • r3m0t
  • csells (Dart support)
  • yanshiyason (Elixir support)
  • Robertof (Rust enhancements, correctness, es6)
  • clintonc (Code quality / brevity, test suite consistency)
  • MarkReeder (JSON formatting)
  • cf512 (bugfixes and feature requests)
  • DainisGorbunovs (MATLAB support)
  • TennyZhuang (data-raw support)

License

MIT © Nick Carneiro

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