1. Converting a JSON POST Request
Backend DeveloperBackground
A developer needs to integrate a payment gateway API that only provides cURL examples in its documentation.
Problem
Manually writing the curl_setopt array for a POST request with custom headers and a JSON payload is tedious and error-prone.
How to use
Paste the cURL command containing -X POST, -H 'Content-Type: application/json', and -d '{"amount": 100}' into the input field, keep 'Pretty-print body' enabled, and copy the generated PHP code.
curlCommand: curl -X POST https://api.stripe.com/v1/charges -H "Authorization: Bearer sk_test" -H "Content-Type: application/json" -d '{"amount": 100, "currency": "usd"}'
prettyBody: true
includeComments: trueOutcome
A complete PHP script using curl_init(), setting CURLOPT_POSTFIELDS with the JSON string, configuring the authorization headers, and executing the request.