Skip to content
curl

HTTP Methods

GET, POST, PUT, and DELETE requests.

By EZ4Code Team
methodgetpost

Code

# GET (default)
curl https://api.example.com/users

# POST with JSON body
curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -d '{"name":"Alice"}'

# PUT
curl -X PUT https://api.example.com/users/1 \
  -H "Content-Type: application/json" \
  -d '{"name":"Alice2"}'

# DELETE
curl -X DELETE https://api.example.com/users/1

Explanation

curl defaults to GET, while -X sets the method explicitly for POST, PUT, DELETE, and others. The -d flag sends a request body and implicitly sets Content-Type to application/x-www-form-urlencoded, so add -H for JSON. A backslash at the end of a line continues the command on the next line in POSIX shells.

More curl Snippets