Wazaterm » Linux Commands » curl

How to use curl Linux command

The curl command is a tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP).

Installation

Debian ubuntu

    
      $ sudo apt install curl
    
  

Usage

How to POST JSON with curl

    
      $ curl -X POST -H "Content-Type: application/json" -d '{"id": "1"}' localhost:3000/api/v1/users
    
  

How to PUT JSON with curl

    
      $ curl -X PUT -H "Content-Type: application/json" -d '{"id": "1", "key": "value"}' localhost:3000/api/v1/users
    
  

How to DELETE JSON with curl

    
      $ curl -X POST -H "Content-Type: application/json" -d '{"id": "1"}' localhost:3000/api/v1/users
    
  

Authenticate with JWT token using curl

    
      $ curl -X POST -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}"  -d '{"id": "1"}' localhost:3000/api/v1/users
    
  

How to GET JSON with basic authentication using curl

    
      $ curl --basic -u $username:$password https://api.example.com/api/sample.json -H "accept: application/json"