Skip to main content

Overview

cURL is a command-line tool for making HTTP requests. It’s perfect for quick tests and shell scripts.

Basic Usage

Simple Request (No API Key)

curl "https://qrgen.maybesurya.live/api/qrgen?data=Hello%20World" -o qr.png
This will generate a QR code for “Hello World” and save it as qr.png.
Spaces and special characters need to be URL-encoded. In the example above, the space becomes %20.

Using an API Key

With Query Parameter

curl "https://qrgen.maybesurya.live/api/qrgen?data=Hello%20World&apiKey=sk_YOUR_API_KEY" -o qr.png

With Header (Better!)

curl "https://qrgen.maybesurya.live/api/qrgen?data=Hello%20World" \
  -H "x-api-key: sk_YOUR_API_KEY" \
  -o qr.png
Using the header keeps your API key out of server logs - much more secure!

Common Use Cases

Website URL

curl "https://qrgen.maybesurya.live/api/qrgen?data=https://maybesurya.dev" \
  -H "x-api-key: YOUR_API_KEY" \
  -o website-qr.png
curl "https://qrgen.maybesurya.live/api/qrgen?data=mailto:hello@example.com" \
  -H "x-api-key: YOUR_API_KEY" \
  -o email-qr.png

Email with Subject

curl "https://qrgen.maybesurya.live/api/qrgen?data=mailto:hello@example.com?subject=Hello%20from%20QR" \
  -H "x-api-key: YOUR_API_KEY" \
  -o email-with-subject-qr.png

Phone Number

curl "https://qrgen.maybesurya.live/api/qrgen?data=tel:+1234567890" \
  -H "x-api-key: YOUR_API_KEY" \
  -o phone-qr.png

SMS Message

curl "https://qrgen.maybesurya.live/api/qrgen?data=sms:+1234567890?body=Hello%20from%20QrX" \
  -H "x-api-key: YOUR_API_KEY" \
  -o sms-qr.png

WiFi Network

curl "https://qrgen.maybesurya.live/api/qrgen?data=WIFI:T:WPA;S:MyNetwork;P:MyPassword;;" \
  -H "x-api-key: YOUR_API_KEY" \
  -o wifi-qr.png

vCard Contact

curl "https://qrgen.maybesurya.live/api/qrgen?data=BEGIN:VCARD%0AVERSION:3.0%0AFN:John%20Doe%0ATEL:+1234567890%0AEMAIL:john@example.com%0AEND:VCARD" \
  -H "x-api-key: YOUR_API_KEY" \
  -o contact-qr.png

Advanced Usage

Save to Specific Directory

curl "https://qrgen.maybesurya.live/api/qrgen?data=test" \
  -H "x-api-key: YOUR_API_KEY" \
  -o /path/to/output/qr.png

Show Response Headers

curl -i "https://qrgen.maybesurya.live/api/qrgen?data=test" \
  -H "x-api-key: YOUR_API_KEY" \
  -o qr.png

Verbose Output (For Debugging)

curl -v "https://qrgen.maybesurya.live/api/qrgen?data=test" \
  -H "x-api-key: YOUR_API_KEY" \
  -o qr.png

Silent Mode (No Progress Bar)

curl -s "https://qrgen.maybesurya.live/api/qrgen?data=test" \
  -H "x-api-key: YOUR_API_KEY" \
  -o qr.png

Shell Script Integration

Bash Script Example

#!/bin/bash

# Configuration
API_KEY="sk_YOUR_API_KEY"
BASE_URL="https://qrgen.maybesurya.live/api/qrgen"

# Function to generate QR code
generate_qr() {
    local data=$1
    local output=$2

    curl -s "$BASE_URL?data=$data" \
        -H "x-api-key: $API_KEY" \
        -o "$output"

    if [ $? -eq 0 ]; then
        echo "✓ QR code generated: $output"
    else
        echo "✗ Failed to generate QR code"
        return 1
    fi
}

# Generate multiple QR codes
generate_qr "https://maybesurya.dev" "website.png"
generate_qr "tel:+1234567890" "phone.png"
generate_qr "mailto:hello@example.com" "email.png"

Batch Processing

#!/bin/bash

API_KEY="sk_YOUR_API_KEY"
BASE_URL="https://qrgen.maybesurya.live/api/qrgen"

# Read URLs from a file and generate QR codes
while IFS= read -r url; do
    filename=$(echo "$url" | sed 's/[^a-zA-Z0-9]/_/g').png

    curl -s "$BASE_URL?data=$url" \
        -H "x-api-key: $API_KEY" \
        -o "$filename"

    echo "Generated: $filename"
    sleep 0.6  # Respect rate limits
done < urls.txt

Error Handling

Check HTTP Status Code

HTTP_CODE=$(curl -s -o qr.png -w "%{http_code}" \
    "https://qrgen.maybesurya.live/api/qrgen?data=test" \
    -H "x-api-key: YOUR_API_KEY")

if [ $HTTP_CODE -eq 200 ]; then
    echo "Success! QR code generated."
elif [ $HTTP_CODE -eq 429 ]; then
    echo "Rate limit exceeded. Please wait."
elif [ $HTTP_CODE -eq 401 ]; then
    echo "Invalid API key."
else
    echo "Error: HTTP $HTTP_CODE"
fi

Using Environment Variables

For security, store your API key in an environment variable:
# Set the environment variable
export QRX_API_KEY="sk_YOUR_API_KEY"

# Use it in your requests
curl "https://qrgen.maybesurya.live/api/qrgen?data=test" \
  -H "x-api-key: $QRX_API_KEY" \
  -o qr.png
Or create a .env file:
# .env file
QRX_API_KEY=sk_YOUR_API_KEY
Load it in your script:
#!/bin/bash
source .env

curl "https://qrgen.maybesurya.live/api/qrgen?data=test" \
  -H "x-api-key: $QRX_API_KEY" \
  -o qr.png
Never commit .env files to version control! Add them to .gitignore.

Tips & Best Practices

✅ Do: - Use environment variables for API keys - URL-encode special characters - Add error handling in scripts - Respect rate limits - Use the -s flag for scripts
❌ Don’t: - Hardcode API keys in scripts - Forget to URL-encode data - Ignore HTTP status codes - Make too many requests - Commit API keys to Git

Next Steps

JavaScript Examples

Use QrX in browser JavaScript

Python Examples

Use QrX in Python applications

Node.js Examples

Use QrX in Node.js applications

API Reference

Complete API documentation