Skip to main content

Command Palette

Search for a command to run...

#1 - GoRest CRUD APIs with curl

Published
4 min read
S

• Possess over 14 years of experience in Quality Engineering, specializing in building test frameworks for complex systems including web applications, REST APIs, and core cloud infrastructure on platforms like Akamai's Linode and Azure.

• Skilled in the development and improvement of automation frameworks for various Web applications, service APIs displaying proficiency in TestNG, PyTest, Selenium, Rest Assured, Jenkins pipeline.

Basics of HTTP and REST APIs

  1. RFC 9110: HTTP Semantics

  2. RFC 9112: HTTP/1.1

  3. Introduction To API

  4. Introduction to REST API


What is cURL?

cURL stands for Client URL.

It is an open-source project focused on building reliable Internet data-transfer tools and libraries. cURL is about moving data between a client and a server using URLs.

curl — the command-line HTTP client

A powerful CLI tool used to:

  • Send HTTP requests (GET, POST, PUT, DELETE, etc.)

  • Work with headers, cookies, authentication, and payloads

  • Debug APIs and automate API test

Command Line options

  • --request or -X → HTTP Method

  • --location or -L → Follow redirects

  • --header or -H → Add header

  • --dump-header or -D → Dump response header

  • --include or -i → include headers in output

  • --output or -o → Write body to file

  • --write-out or -w → Write meta data

    • %{http_code}

    • %{time_total}

  • –data or -d → Send request body

  • --json → Json shortcut equivalent to -H "Content-Type: application/json" -d '{...}'

  • --silent or -s → Silent mode

  • --show-error or -S → Show error only

  • --verbose or -v → verbose

  • --fail or -f → Fail on HTTP error (Exits with non-zero status on 4xx/5xx.)

  • --retry → Retries on transient failures. (network errors or timeout)

    • --retry-delay → how long to sleep (in seconds) before trying again after a failed attempt.
  • --max-time → Kills request after N seconds.


GoRest CRUD APIs

GoRest APIs

  1. GoRest - https://gorest.co.in/

  2. Get your access token from - https://gorest.co.in/my-account/access-tokens

Setup

export API_TOKEN="<<gorest-access-token>>"
BASE_URI="https://gorest.co.in/public/v2"

List Users

Curl command

curl --location
--request GET --silent --dump-header headers.txt --output response.json --write-out "Status Code: %{http_code}\n" --url "$BASE_URI/users”

Making GET request

Response Headers

Response Body

Display user ids


Create User

Curl command - Ensure that email id is unique

curl --location  \
--request POST \
--header "Authorization: Bearer $API_TOKEN" \
--silent \
--dump-header headers.txt \
--output response.json \
--write-out "Status Code: %{http_code}\n" \
--url "$BASE_URI/users" \
--json '{
        "name": "Test User",
        "email": "test_user2@testing.example",
        "gender": "male",
        "status": "inactive"
}'


Get User

curl command - update user id

curl --location  \
--request GET \
--header "Authorization: Bearer $API_TOKEN" \
--silent \
--dump-header headers.txt \
--output response.json \
--write-out "Status Code: %{http_code}\n" \
--url "$BASE_URI/users/userId"


Update User

curl command - update user id

| curl --location \
--request PUT \
--header "Authorization: Bearer $API_TOKEN" \
--silent \
--dump-header headers.txt \
--output response.json \
--write-out "Status Code: %{http_code}\n" \
--url "$BASE_URI/users/userId" \
--json '{
"status": "active"
}' | | --- | | |


Delete User

curl command - update user id

curl --location  \
--request DELETE \
--header "Authorization: Bearer $API_TOKEN" \
--silent \
--dump-header headers.txt \
--output response.json \
--write-out "Status Code: %{http_code}\n" \
--url "$BASE_URI/users/userId"

In this article I used cURL to interact with GoRest CRUD APIs.

Why start with cURL?

Because cURL forces you to understand the raw HTTP contract:

  • Endpoint structure

  • HTTP methods (GET, POST, PUT, DELETE)

  • Headers (Authorization, Content-Type)

  • Request payloads

  • Response headers and body

  • Status codes

If you don’t understand APIs at this level, automation will only hide problems—not solve them.

Limitations of cURL for API Testing

cURL is excellent for:

  • Manual exploration

  • Debugging

  • Learning HTTP

  • Reproducing issues quickly

But it breaks down fast when testing grows.

You quickly hit problems like:

  • No assertions (only visual inspection)

  • No test structure

  • No reuse of setup (tokens, base URLs)

  • No reporting

  • No easy CI integration

In the rest of the article in this series we will use pytest + requests.

pytest + requests help to write simple Python tests that call APIs, check the responses, and confirm everything works as expected—automatically and repeatedly.

What’s Next in This Series

In the next sections, this article series will evolve:

  • Move cURL logic into Python requests

  • Introduce pytest test cases

  • Add assertions on response structure and data

  • Refactor setup (tokens, base URI) into fixtures

  • Build toward a clean, maintainable API test framework