Curlconverter
:curly_loop: :arrow_right: :heavy_minus_sign: Translate cURL command lines into parameters for use with httr or actual httr calls (R)
Install / Use
/learn @hrbrmstr/CurlconverterREADME
curlconverter
Tools to Transform ‘cURL’ Command-Line Calls to ‘httr’ Requests
Description
Deciphering web/‘REST’ ‘API’ and ‘XHR’ calls can be tricky, which is one reason why internet browsers provide “Copy as cURL” functionality within their “Developer Tools”pane(s). These ‘cURL’ command-lines can be difficult to wrangle into an ‘httr’ ‘GET’ or ‘POST’ request, but you can now “straighten” these ‘cURLs’ either from data copied to the system clipboard or by passing in a vector of ‘cURL’ command-lines and getting back a list of parameter elements which can be used to form ‘httr’ requests. These lists can be passed to another function to automagically make ‘httr’ functions.
WIP
This is the path back to CRAN and to 1.0.0.
The V8 dependency has been removed and the package now uses docopt.
This will make it easier to install on many systems and enable rapid
addition of support for new cURL command-line parameters.
The “HAR” functions are not working well with the new methods but will be for full release.
What’s Inside The Tin
The following functions are implemented:
straighten: convert one or more “Copy as cURL” command lines into useful dataparse_query: parse URL query parameters into a named listmake_req: turn parsed cURL command lines into ahttrrequest functions (i.e. returns working R functions)
The following functions are implemented:
Installation
devtools::install_github("hrbrmstr/curlconverter")
Usage
library(curlconverter)
library(jsonlite)
library(httr)
# current verison
packageVersion("curlconverter")
## [1] '1.0.0'
Simple example using a call to https://httpbin.org/headers:
httpbinrhcurl <- "curl 'https://httpbin.org/headers' -H 'pragma: no-cache' -H 'accept-encoding: gzip, deflate, sdch' -H 'accept-language: en-US,en;q=0.8' -H 'upgrade-insecure-requests: 1' -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.39 Safari/537.36' -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'cache-control: no-cache' -H 'referer: https://httpbin.org/' --compressed"
straight <- straighten(httpbinrhcurl)
## curl 'https://httpbin.org/headers' -H 'pragma: no-cache' -H 'accept-encoding: gzip, deflate, sdch' -H 'accept-language: en-US,en;q=0.8' -H 'upgrade-insecure-requests: 1' -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.39 Safari/537.36' -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'cache-control: no-cache' -H 'referer: https://httpbin.org/' --compressed
res <- make_req(straight)
# or
straighten(httpbinrhcurl) %>%
make_req() -> res
## curl 'https://httpbin.org/headers' -H 'pragma: no-cache' -H 'accept-encoding: gzip, deflate, sdch' -H 'accept-language: en-US,en;q=0.8' -H 'upgrade-insecure-requests: 1' -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.39 Safari/537.36' -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'cache-control: no-cache' -H 'referer: https://httpbin.org/' --compressed
toJSON(content(res[[1]](), as="parsed"), auto_unbox = TRUE, pretty=TRUE)
## {
## "headers": {
## "Accept": "application/json, text/xml, application/xml, */*,text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
## "Accept-Encoding": "gzip, deflate, sdch",
## "Accept-Language": "en-US,en;q=0.8",
## "Cache-Control": "no-cache",
## "Connection": "close",
## "Host": "httpbin.org",
## "Pragma": "no-cache",
## "Referer": "https://httpbin.org/",
## "Upgrade-Insecure-Requests": "1",
## "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.39 Safari/537.36"
## }
## }
Slightly more complex one:
toJSON(straighten("curl 'http://financials.morningstar.com/ajax/ReportProcess4HtmlAjax.html?&t=XNAS:MSFT®ion=usa&culture=en-US&cur=&reportType=is&period=12&dataType=A&order=asc&columnYear=5&curYearPart=1st5year&rounding=3&view=raw&r=973302&callback=jsonp1454021128757&_=1454021129337' -H 'Cookie: JSESSIONID=5E43C98903E865D72AA3C2DCEF317848; sfhabit=asc%7Craw%7C3%7C12%7CA%7C5%7Cv0.14; ScrollY=0' -H 'DNT: 1' -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_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36' -H 'Accept: text/javascript, application/javascript, */*' -H 'Referer: http://financials.morningstar.com/income-statement/is.html?t=MSFT®ion=usa&culture=en-US' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' --compressed"), auto_unbox = TRUE, pretty=TRUE)
## curl 'http://financials.morningstar.com/ajax/ReportProcess4HtmlAjax.html?&t=XNAS:MSFT®ion=usa&culture=en-US&cur=&reportType=is&period=12&dataType=A&order=asc&columnYear=5&curYearPart=1st5year&rounding=3&view=raw&r=973302&callback=jsonp1454021128757&_=1454021129337' -H 'Cookie: JSESSIONID=5E43C98903E865D72AA3C2DCEF317848; sfhabit=asc%7Craw%7C3%7C12%7CA%7C5%7Cv0.14; ScrollY=0' -H 'DNT: 1' -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_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36' -H 'Accept: text/javascript, application/javascript, */*' -H 'Referer: http://financials.morningstar.com/income-statement/is.html?t=MSFT®ion=usa&culture=en-US' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' --compressed
## [
## {
## "url": "http://financials.morningstar.com/ajax/ReportProcess4HtmlAjax.html?&t=XNAS:MSFT®ion=usa&culture=en-US&cur=&reportType=is&period=12&dataType=A&order=asc&columnYear=5&curYearPart=1st5year&rounding=3&view=raw&r=973302&callback=jsonp1454021128757&_=1454021129337",
## "method": "GET",
## "cookies": {
## "JSESSIONID": "5E43C98903E865D72AA3C2DCEF317848",
## "sfhabit": "asc%7Craw%7C3%7C12%7CA%7C5%7Cv0.14",
## "ScrollY": "0"
## },
## "username": {},
## "password": {},
## "user_agent": {
## "DNT": "1",
## "Accept-Encoding": "gzip, deflate, sdch",
## "Accept-Language": "en-US,en;q=0.8",
## "Accept": "text/javascript, application/javascript, */*",
## "Referer": "http://financials.morningstar.com/income-statement/is.html?t=MSFT®ion=usa&culture=en-US",
## "X-Requested-With": "XMLHttpRequest",
## "Connection": "keep-alive",
## "Cache-Control": "max-age=0"
## },
## "referer": {},
## "data": {},
## "headers": {
## "DNT": "1",
## "Accept-Encoding": "gzip, deflate, sdch",
## "Accept-Language": "en-US,en;q=0.8",
## "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36",
## "Accept": "text/javascript, application/javascript, */*",
## "Referer": "http://financials.morningstar.com/income-statement/is.html?t=MSFT®ion=usa&culture=en-US",
## "X-Requested-With": "XMLHttpRequest",
## "Connection": "keep-alive",
## "Cache-Control": "max-age=0"
## },
## "verbose": false,
## "url_parts": {
## "scheme": "http",
## "hostname": "financials.morningstar.com",
## "port": {},
## "path": "ajax/ReportProcess4HtmlAjax.html",
## "query": {
## "1": "",
## "t": "XNAS:MSFT",
## "region": "usa",
## "culture": "en-US",
## "cur": "",
## "reportType": "is",
## "period": "12",
## "dataType": "A",
## "order": "asc",
## "columnYear": "5",
## "curYearPart": "1st5year",
## "rounding": "3",
## "view": "raw",
## "r": "973302",
## "callback": "jsonp1454021128757",
## "_": "1454021129337"
## },
## "params": {},
## "fragment": {},
## "username": {},
## "password": {}
## },
## "orig_curl": "curl 'http://financials.morningstar.com/ajax/ReportProcess4HtmlAjax.html?&t=XNAS:MSFT®ion=usa&culture=en-US&cur=&reportType=is&period=12&dataType=A&order=asc&columnYear=5&curYearPart=1st5year&rounding=3&view=raw&r=973302&callback=jsonp1454021128757&_=1454021129337' -H 'Cookie: JSESSIONID=5E43C98903E865D72AA3C2DCEF317848; sfhabit=asc%7Craw%7C3%7C12%7CA%7C5%7Cv0.14; ScrollY=0' -H 'DNT: 1' -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_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36' -H 'Accept: text/javascript, appli
Related Skills
node-connect
351.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
351.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
351.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
