DeveloperBreeze

Various cURL Examples for API Interactions

# Update resource with PUT request
curl -X PUT https://api.example.com/resource/123 \
    -H 'Content-Type: application/json' \
    -d '{"key": "updated_value"}'

# Retrieve data with GET request
curl https://api.example.com/data

# Send data with POST request to a form endpoint
curl -X POST https://api.example.com/form-endpoint \
    -d 'param1=value1&param2=value2'

# Delete resource with DELETE request and Authorization header
curl -X DELETE https://api.example.com/resource/456 \
    -H 'Authorization: Bearer your_access_token'

# Upload a file with POST request to an upload endpoint
curl -X POST https://api.example.com/upload-endpoint \
    -H 'Content-Type: multipart/form-data' \
    -F 'file=@/path/to/your/file.txt'

# Send JSON data with POST request to a secured endpoint with headers and authorization
curl -X POST https://api.example.com/post-endpoint \
    -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer your_access_token' \
    -d '{"username": "john_doe", "password": "secretpassword"}'

# Send JSON data with POST request to an endpoint with cookies
curl -X POST https://example.com/api/endpoint \
    -H 'Content-Type: application/json' \
    -H 'Cookie: sessionid=your_session_id' \
    -d '{"key1": "value1", "key2": "value2"}'

Continue Reading

Handpicked posts just for you — based on your current read.

Etherscan vs Infura: Choosing the Right API for Your Blockchain Application

Use Infura when you need to interact with the Ethereum blockchain in real-time. Infura allows you to send transactions, deploy contracts, and interact with smart contracts. It is essential for decentralized applications (dApps) and any use case where you need to write to the blockchain.

const ethers = require('ethers');

// Replace with your Infura Project ID
const infuraProvider = new ethers.JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');

// Replace with your wallet's private key
const privateKey = 'YOUR_PRIVATE_KEY';

// Create a wallet instance and connect it to Infura
const wallet = new ethers.Wallet(privateKey, infuraProvider);

// Replace with the recipient's Ethereum address
const recipientAddress = '0xRecipientEthereumAddress';

// Amount to send (in Ether)
const amountInEther = '0.01';

async function sendTransaction() {
  try {
    const tx = {
      to: recipientAddress,
      value: ethers.utils.parseEther(amountInEther),
      gasLimit: 21000, // Gas limit for a basic transaction
      gasPrice: await infuraProvider.getGasPrice() // Get current gas price from Infura
    };

    // Send the transaction
    const transaction = await wallet.sendTransaction(tx);
    console.log('Transaction Hash:', transaction.hash);

    // Wait for the transaction to be mined
    const receipt = await transaction.wait();
    console.log('Transaction Confirmed:', receipt);
  } catch (error) {
    console.error('Error sending transaction:', error);
  }
}

sendTransaction();

Oct 24, 2024 Tutorial

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!