How to Perform REST API Requests and Debugging Using cURL CLI?

Asked 19 days ago Updated 20 days ago 93 views

0

cURL is one of the most widely used command-line tools for transferring data with URLs. It is ideal for quick REST API testing and debugging straight from the CMD terminal.

How to send custom HTTP POST and GET requests using cURL?

Below are common cURL commands used for testing RESTful services:

1. GET Request with Headers

curl -X GET "https://api.example.com/v1/users" \
  -H "Accept: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN"

2. POST Request with JSON Body

curl -X POST "https://api.example.com/v1/users" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Doe",
    "email": "john@example.com"
  }'

Using the -i flag includes HTTP response headers in the output, which helps verify status codes and caching policies.

0 Answers


Write Your Answer