Online tool to convert `curl` requests to Laravel `Http` requests

Related tags

HTTP curl-converter
Overview

curl Converter

Another bit of automation from Shift to convert curl requests to Laravel Http requests.

This project is a WIP. You may follow along with development in Jason McCreary's live streams.

Contributing

Code contributions may be made by submitting a Pull Request against the main branch. Submitted PRs should:

  • Explain the change, ideally using before and after examples.
  • Pass all build steps.
  • Ideally, Include tests which verify the change.

You may also contribute by opening an issue to report a bug or suggest a new feature.

If you are so inclined, you may also say "thanks" or proclaim your love for Shift on Twitter.

Comments
  • Accept data-raw

    Accept data-raw

    Added support for providing data-raw according to #8.

    My reasoning for the proposed solution is that they should never be present simultaneously, and if data-raw isn't present, then go for default behavior with the -d|data-option, giving data-raw a slight precedence over data.

    opened by dnkmdg 4
  • `--location` (follow redirects) is not necessary with `Http` client; what to do?

    `--location` (follow redirects) is not necessary with `Http` client; what to do?

    Just wondering how you want to handle the --location flag. With cURL, it means "follow any redirects" but the Laravel Http client does this by default.

    My thinking is to just silently accept and discard it so that it doesn't throw an error like this:

    Screen Shot 2022-10-11 at 10 39 23 AM

    Thoughts? I'm happy to add this "feature" if you're ok with the idea of just ignoring it.

    opened by nexxai 4
  • Add support for 'data-raw'

    Add support for 'data-raw'

    Added support for providing data-raw according to #8.

    My reasoning for the proposed solution is that they should never be present simultaneously, and if data-raw isn't present, then go for default behavior with the -d|data-option, giving data-raw a slight precedence over data.

    opened by dnkmdg 3
  • Add support for 'data-raw'

    Add support for 'data-raw'

    Added support for providing data-raw according to #8.

    My reasoning for the proposed solution is that they should never be present simultaneously, and if data-raw isn't present, then go for default behavior with the -d|data-option, giving data-raw a slight precedence over data.

    opened by dnkmdg 3
  • Add support for more options

    Add support for more options

    When copying request from Chrome DevTools the options --insecure and --compressed are sometimes present, and was not recognized by the package.

    The --insecure option should primarily be present when posting/fetching data from a non-SSL endpoint. The --compressed option indicates that cURL accepts any encoded response, equivalent to CURLOPT_ENCODING = ""

    I added support for these two in the options gatherer. They won't have any effect on the standard HTTP call, thus are simply ignored.

    Removed notes about #8

    opened by dnkmdg 3
  • Parse query string into data array

    Parse query string into data array

    This PR extracts the URL query string to the data array in the Laravel HTTP client.

    For example,

    curl "https://api.postmarkapp.com/messages/[email protected]&count=50&offset=0&tag=welcome&status=sent&todate=2015-01-12&fromdate=2015-01-01" -X GET

    currently yields this HTTP request:

    Http::get('https://api.postmarkapp.com/messages/[email protected]&count=50&offset=0&tag=welcome&status=sent&todate=2015-01-12&fromdate=2015-01-01');
    

    Which technically works but it not very readable. Now it will instead output this:

    Http::get('https://api.postmarkapp.com/messages/outbound', [
            'recipient' => '[email protected]',
            'count' => '50',
            'offset' => '0',
            'tag' => 'welcome',
            'status' => 'sent',
            'todate' => '2015-01-12',
            'fromdate' => '2015-01-01',
        ]);
    

    Which makes query string parameters much more readable and easy to edit the individual values in the code.

    NOTE: This uses PHP's parse_url. This creates a refactoring opportunity in App/Models/Request on line 65 to use it to get the Http Basic Auth username and password instead of exploding the raw URL string.

    opened by x7ryan 3
  • `--data-raw` not supported

    `--data-raw` not supported

    Many tools such as postman use data-raw. Maybe worth adding support for this, esp for json requests?

    curl --request POST 'https://api.com' \
    --header 'Accept: application/json' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "messages": [
            "a",
            "b",
            "c"
        ]
    }'
    
    enhancement 
    opened by atymic 2
  • curlconverter

    curlconverter

    There's no Laravel output, feel free to contribute one, but we do convert to PHP's cURL library https://curlconverter.com/php/

    The website also links to other projects doing the same thing. This is the 3rd project called "curl converter" that I know of. We only link to projects that work on the client, there are other projects (including this one) that we don't link to because they upload curl commands to a server they control, which would allow them to silently nefariously log the curl command and if you paste a command with a cookie or auth token in it, that would be bad.

    https://github.com/curlconverter/curlconverter

    opened by verhovsky 1
  • Support `--data-raw`

    Support `--data-raw`

    The --data-raw option takes some interpretation. The curl docs do not state that it is mutually exclusive from --data. From a quick tests, it seems curl merges the data when called with both --data and --data-raw.

    With that said, the common use case for --data-raw seems to be independent. When passed alone, this is the exact data to send in the request payload.

    This PR adds support for --data-raw to the specification above - parsing it as form data when mixed with --data or sending it as the raw body when used independently.

    opened by jasonmccreary 1
  • Dealing with POST data with multiple keys that are the same value.

    Dealing with POST data with multiple keys that are the same value.

    Hi there, this is a really useful project thank you!

    I've just tried with one of my more troublesome POST queries I have to make and I'm having a problem getting it to convert.

    I need to make a POST request to a URL with the following as the payload. This is taken directly as a copy from Chrome using devtools.

    The Raw format

    Print=Print&selection=aerodromeOrder&aerodrome=eick&Basket=false&icao=eick&check=on&order=eickei+&order=f1780614+&order=f1738132+&order=b1738132+&order=f1928002+&order=f1736502+&order=b1736502+&order=f1736540+&order=f1736509+&order=b1736509+&order=f1736520+&order=b1736520+&order=f1736511+&order=b1736511+&order=f1736512+&order=b1736512+&order=f1736518+&order=b1736518+&order=f1736521+&order=b1736521+&order=f1736523+&order=f1736513+&order=b1736513+&order=f1736515+&order=b1736515+&order=f1736536+&order=b1736536+&order=f1896451+&order=b1896451+&order=f1736525+&order=b1736525+&order=f1758356+
    

    Image from chrome dev tools:

    CleanShot 2022-10-13 at 08 36 30

    As you can see there are multiple order keys in the data payload.

    However when I try and use this package to convert this to Laravel HTTP format, only the last order key survives.

    CleanShot 2022-10-13 at 08 37 06

    Whats the best way to deal with multiple keys having the same name?

    This was the original request I tried to convert, I've just removed some excessive headers.

    curl 'https://viewer.flightsupport.com/servlet/PrintServlet' \
      -H 'Content-Type: application/x-www-form-urlencoded' \
      -H 'Cookie: REDACTED' \
      -H 'Origin: https://viewer.flightsupport.com' \
      -H 'Pragma: no-cache' \
      -H 'Referer: https://viewer.flightsupport.com/frames/home.jsp' \
      -H 'Sec-Fetch-Dest: document' \
      -H 'Sec-Fetch-Mode: navigate' \
      -H 'Sec-Fetch-Site: same-origin' \
      -H 'Sec-Fetch-User: ?1' \
      -H 'Upgrade-Insecure-Requests: 1' \
      -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36' \
      --data-raw 'Print=Print&selection=aerodromeOrder&aerodrome=eick&Basket=false&icao=eick&check=on&order=eickei+&order=f1780614+&order=f1738132+&order=b1738132+&order=f1928002+&order=f1736502+&order=b1736502+&order=f1736540+&order=f1736509+&order=b1736509+&order=f1736520+&order=b1736520+&order=f1736511+&order=b1736511+&order=f1736512+&order=b1736512+&order=f1736518+&order=b1736518+&order=f1736521+&order=b1736521+&order=f1736523+&order=f1736513+&order=b1736513+&order=f1736515+&order=b1736515+&order=f1736536+&order=b1736536+&order=f1896451+&order=b1896451+&order=f1736525+&order=b1736525+&order=f1758356+'
    
    
    opened by jonnywilliamson 1
  • php curl support

    php curl support

    Would be great if it could also support for php curl to Http facade. e.g.

    $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/includes/api.php'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query( array( 'action' => 'GetProducts', // See https://developers.whmcs.com/api/authentication 'username' => 'IDENTIFIER_OR_ADMIN_USERNAME', 'password' => 'SECRET_OR_HASHED_PASSWORD', 'pid' => '1', 'responsetype' => 'json', ) ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch);

    becomes

    $result = Http::asForm()->post('https://www.example.com/includes/api.php', [ 'action' => 'GetProducts', 'username' => 'IDENTIFIER_OR_ADMIN_USERNAME', 'password' => 'SECRET_OR_HASHED_PASSWORD', 'pid' => '1', 'responsetype' => 'json', ])->json();

    opened by chadleverington 1
  • The

    The "--url" option does not exist.

    Following CURL request from Auth0 examples is not working:

    curl --request POST --url https://signalcortex.us.auth0.com/oauth/token --header 'content-type: application/json' --data '{"client_id":"qwertyuiopasdfghqwertyuiopasdfgh","client_secret":"qwertyuiopasdfghqwertyuiopasdfghqwertyuiopasdfghqwertyuiopasdfgh","audience":"https://signalcortex.us.auth0.com/api/v2/","grant_type":"client_credentials"}'
    
    opened by oleg-tondone 1
  • support `-T` option

    support `-T` option

    From the Transitor API docs:

    curl -v -X PUT \
      -H "Content-Type: audio/mpeg" \
      -T /path/to/your/audio/Episode1.mp3 \
      "upload_url_from_authorize_upload"
    

    The Content-Type header and -T option can be replaced with withBody($contents, 'audio/mpeg') where $contents is the complete file contents. (Like via file_get_contents)

    enhancement 
    opened by joelclermont 1
  • The

    The "--data-binary" option does not exist.

    curl 'https://graphigo.prd.dlive.tv/' --data-binary '{"query":"query{userByDisplayName(displayname: "Potato") {username displayname avatar partnerStatus followers{totalCount}}}"}'

    enhancement 
    opened by MuhammadUsman678 2
  • Better handling of values containing backslashes

    Better handling of values containing backslashes

    Currently backslashes (and possibly other characters) are being lost from values as they are passed through Artisan. These need to be escaped so they are preserved in the final output. An appropriately placed call to addslashes should to the trick.

    Example curl command:

    curl --request POST https://example.com/pdf/extract --header 'Content-Type: multipart/form-data' --form 'file=C:\Users\secret\files\007.pdf'
    
    good first issue 
    opened by jasonmccreary 5
  • -c, --cookie-jar <filename> not supported

    -c, --cookie-jar not supported

    I have just tested the new genius feature to convert cURL call to Laravel HTTP request and faced with the issue, the "-c" option does not exist. This is the cookie file handling feature of the cURL function.

    Example cURL call: curl -v -F [email protected] -c ./cookies.txt -o response.pdf https://www.szamlazz.hu/szamla/

    Reference: https://docs.szamlazz.hu/#post-request

    enhancement 
    opened by trianity 2
Releases(v0.4.0)
  • v0.4.0(Oct 13, 2022)

  • v0.3.0(Oct 11, 2022)

    Added

    • Support -G and --data-urlencode (https://github.com/laravel-shift/curl-converter/commit/6b0e39b6da1904afefc5e427ec837e9b724966fb)
    • Support --location and -L options (#11)

    Fixed

    • Default URL scheme to https (https://github.com/laravel-shift/curl-converter/commit/b979027137d279cd1a500d51b5d8558fdc5d93b6)
    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Sep 28, 2022)

    Added

    • Add connectTimeout() and timeout() options (#5)

    Fixed

    • Add spacing around code output (https://github.com/laravel-shift/curl-converter/commit/3e4118abd07e07e576ad806b0817f47d0bb8179b)
    • Make command available all the time (https://github.com/laravel-shift/curl-converter/commit/de561a12e11ff1a7ec0a273e80b56513e9d174cc)
    Source code(tar.gz)
    Source code(zip)
  • v0.1(Sep 2, 2022)

Owner
Laravel Shift
Laravel Shift is an automated service for upgrading your Laravel applications.
Laravel Shift
PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs

PHP Curl Class: HTTP requests made easy PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs. Installation Requirements Quic

null 3.1k Jan 5, 2023
A Chainable, REST Friendly, PHP HTTP Client. A sane alternative to cURL.

Httpful Httpful is a simple Http Client library for PHP 7.2+. There is an emphasis of readability, simplicity, and flexibility – basically provide the

Nate Good 1.7k Dec 21, 2022
Simple HTTP cURL client for PHP 7.1+ based on PSR-18

Simple HTTP cURL client for PHP 7.1+ based on PSR-18 Installation composer require sunrise/http-client-curl QuickStart composer require sunrise/http-f

Sunrise // PHP 15 Sep 5, 2022
🐼 Framework agnostic package using asynchronous HTTP requests and PHP generators to load paginated items of JSON APIs into Laravel lazy collections.

Framework agnostic package using asynchronous HTTP requests and generators to load paginated items of JSON APIs into Laravel lazy collections.

Andrea Marco Sartori 61 Dec 3, 2022
Requests for PHP is a humble HTTP request library. It simplifies how you interact with other sites and takes away all your worries.

Requests for PHP Requests is a HTTP library written in PHP, for human beings. It is roughly based on the API from the excellent Requests Python librar

null 3.5k Dec 31, 2022
Requests for PHP is a humble HTTP request library. It simplifies how you interact with other sites and takes away all your worries.

Requests for PHP Requests is a HTTP library written in PHP, for human beings. It is roughly based on the API from the excellent Requests Python librar

null 3.5k Dec 31, 2022
↪️ Bypass for PHP creates a custom HTTP Server to return predefined responses to client requests

Bypass for PHP provides a quick way to create a custom HTTP Server to return predefined responses to client requests.Useful for tests with Pest PHP or PHPUnit.

CiaReis 101 Dec 1, 2022
Application for logging HTTP and DNS Requests

Request Logger Made by Adam Langley ( https://twitter.com/adamtlangley ) What is it? Request logger is a free and open source utility for logging HTTP

null 13 Nov 28, 2022
librestful is a virion for PocketMine servers that make easier, readable code and for async http requests.

librestful is a virion for PocketMine servers that make easier, readable code for async rest requests.

RedMC Network 17 Oct 31, 2022
Provides an easy interface for performing Hyper-Text Transfer Protocol (HTTP) requests

laminas-http provides the HTTP message abstraction used by laminas-mvc, and also provides an extensible, adapter-driven HTTP client library.

Laminas Project 33 Aug 27, 2022
Requests - a HTTP library written in PHP, for human beings

Requests is a HTTP library written in PHP, for human beings. It is roughly based on the API from the excellent Requests Python library. Requests is ISC Licensed (similar to the new BSD license) and has no dependencies, except for PHP 5.6+.

WordPress 3.5k Jan 6, 2023
Custom PHP curl library for the Laravel 5 framework - developed by Ixudra

ixudra/curl Custom PHP cURL library for the Laravel 4 or 5 framework - developed by Ixudra. The package provides an easy interface for sending cURL re

Jan Oris 556 Jan 6, 2023
Declarative HTTP Clients using Guzzle HTTP Library and PHP 8 Attributes

Waffler How to install? $ composer require waffler/waffler This package requires PHP 8 or above. How to test? $ composer phpunit Quick start For our e

Waffler 3 Aug 26, 2022
The best php curl library.

中文文档 About Implemented by using php-curl internal io event with high performance,high universality,high extensibility which especially suitable for ma

Ares 431 Dec 12, 2022
PHP cURL for feed Instagram Graph API

php-curl-instagram-graph PHP cURL for feed Instagram Graph API Script made based on the new (2020) Instagram API that requires authorization token gen

null 12 Apr 13, 2022
Simple PHP curl wrapper class

php-curl The smallest possible OOP wrapper for PHP's curl capabilities. Note that this is not meant as a high-level abstraction. You should still know

Andreas Lutro 243 Dec 5, 2022
This library provides an object-oriented wrapper of the PHP cURL extension

PHP Curl Class This library provides an object-oriented wrapper of the PHP cURL extension. If you have questions or problems with installation or usag

PHP MOD 321 Dec 30, 2022
The best php curl library.

中文文档 About Implemented by using php-curl internal io event with high performance,high universality,high extensibility which especially suitable for ma

Ares 431 Dec 12, 2022
PHP Curl ile letgo api kütüphanesi oluşturuldu. php ile letgo giriş yap.

Kendi LETGO API ile işlemler gerçekleştirelim. // email işlemleri $server = 'imap.gmail.com'; $user = '[email protected]'; $pass = 'password'; $port = 9

Görkem Bayraktar 2 Nov 3, 2022