cURL Examples

Quick examples for testing Flux APIs with cURL.

Basic GET Request

curl -X GET \
  'https://useflux.site/api/v2/gateway/abc123/posts/1' \
  -H 'x-flux-payment-tx: 0x1234...' \
  -H 'x-flux-signature: 0x5678...'

POST Request with Body

curl -X POST \
  'https://useflux.site/api/v2/gateway/abc123/posts' \
  -H 'x-flux-payment-tx: 0x1234...' \
  -H 'x-flux-signature: 0x5678...' \
  -H 'Content-Type: application/json' \
  -d '{
    "title": "My Post",
    "body": "Post content",
    "userId": 1
  }'

With Path Parameters

curl -X GET \
  'https://useflux.site/api/v2/gateway/abc123/users/123/posts' \
  -H 'x-flux-payment-tx: 0x1234...' \
  -H 'x-flux-signature: 0x5678...'

With Query Parameters

curl -X GET \
  'https://useflux.site/api/v2/gateway/abc123/posts?userId=1&_limit=10' \
  -H 'x-flux-payment-tx: 0x1234...' \
  -H 'x-flux-signature: 0x5678...'

Complete Example with Payment

# 1. Send payment (using cast from Foundry)
TX_HASH=$(cast send 0xRecipientAddress \
  --value 0.001ether \
  --private-key $PRIVATE_KEY \
  --rpc-url https://mainnet.base.org \
  | grep "transactionHash" | awk '{print $2}')

# 2. Sign message
MESSAGE="Flux API Authorization\n\nTransaction: $TX_HASH\nService: endpoint123\n\nBy signing this message, you authorize Flux to use this payment for the specified API service."

SIGNATURE=$(cast wallet sign "$MESSAGE" --private-key $PRIVATE_KEY)

# 3. Call API
curl -X GET \
  'https://useflux.site/api/v2/gateway/abc123/posts/1' \
  -H "x-flux-payment-tx: $TX_HASH" \
  -H "x-flux-signature: $SIGNATURE"

Error Handling

# Save response to file
curl -X GET \
  'https://useflux.site/api/v2/gateway/abc123/posts/1' \
  -H 'x-flux-payment-tx: 0x1234...' \
  -H 'x-flux-signature: 0x5678...' \
  -o response.json \
  -w "HTTP Status: %{http_code}\n"

# Check status code
STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
  -X GET \
  'https://useflux.site/api/v2/gateway/abc123/posts/1' \
  -H 'x-flux-payment-tx: 0x1234...' \
  -H 'x-flux-signature: 0x5678...')

if [ $STATUS -eq 200 ]; then
  echo "Success!"
else
  echo "Error: $STATUS"
fi

Last updated