cURL Examples

cURL Examples for API Requests

Use these practical cURL examples, cURL samples, and conversion-ready commands for GET requests, POST JSON, authentication, cookies, timeouts, SSL troubleshooting, HTTP 400 debugging, PHP, and Python requests.

Basic GET cURL Example

Use a GET request when an API endpoint only needs path or query parameters.

curl -H 'Accept: application/json' https://api.example.com/users

cURL POST JSON Example

Use this for API create or update calls that send a JSON request body.

curl -X POST https://api.example.com/users \
  -H 'Content-Type: application/json' \
  --data-raw '{"name":"Ada","active":true}'

cURL Bearer Token Example

Use an Authorization header for Bearer tokens, API keys, OAuth access tokens, and protected API calls.

curl https://api.example.com/account \
  -H 'Authorization: Bearer demo-token' \
  -H 'Accept: application/json'

cURL Timeout Example

Use --connect-timeout for connection setup and --max-time for the full request budget.

curl --connect-timeout 3 --max-time 15 \
  -H 'Accept: application/json' \
  https://api.example.com/slow-report

cURL Ignore SSL Example

The -k flag disables certificate verification. It is useful for local testing but risky for production traffic.

curl -k -L \
  -H 'Accept: application/json' \
  https://self-signed.badssl.example/api/status

HTTP 400 Bad Request cURL Example

400 responses often come from malformed JSON, wrong content type, missing auth, or invalid query parameters.

curl -X POST https://api.example.com/users \
  -H 'Content-Type: application/json' \
  --data-raw '{"email":"not-an-email","age":"wrong-type"}'

PHP cURL Timeout Example

Convert timeout flags into PHP cURL options such as CURLOPT_TIMEOUT and CURLOPT_CONNECTTIMEOUT.

curl --connect-timeout 5 --max-time 30 \
  -H 'Accept: application/json' \
  https://api.example.com/invoices

cURL to Python Requests Example

Use this pattern when converting API documentation examples into Python requests code.

curl -X POST https://api.example.com/search \
  -H 'Authorization: Bearer demo-token' \
  -H 'Content-Type: application/json' \
  --data-raw '{"q":"curl to python","limit":10}'

More cURL Example Categories

Browser Copy as cURL

Convert long browser DevTools requests with cookies, compressed flags, user agents, and security headers.

Headers and Cookies

Understand -H, Cookie headers, -b, Accept, User-Agent, and session values.

Form Data and File Uploads

Convert multipart -F requests with text fields, local file placeholders, filenames, and content types.

URL Encoded Data

Use --data-urlencode and -G for encoded query strings and form request bodies.

Supported cURL Options

Check which flags are parsed, converted, ignored with warnings, or need manual review in generated code.

curlconverter Alternative

Compare library-first conversion with an online workflow built for quick paste, warnings, and readable output.

cURL Examples FAQ

Can I convert these cURL examples into code?

Yes. Open any sample in the converter and choose JSON, Python, JavaScript, Node.js, PHP, Java, C#, Go, Ruby, Swift, or Rust output.

Do these examples execute the request?

No. The converter parses and formats command text. It does not run shell commands or call the target API endpoint.

Should I paste real tokens or cookies?

Use redacted or test credentials. Browser Copy as cURL can include live cookies, Authorization headers, and session IDs.