Skip to main content
This tutorial builds a test file that exercises all four CRUD operations against the JSONPlaceholder API. You will learn how to define variables, write assertions, capture response values, and chain requests with dependencies.

Prerequisites

The Complete Test File

Here is the full test file you will build step by step. Create a file called crud.http:
crud.http

Step-by-Step Breakdown

1

Define variables

The @baseUrl variable at the top of the file stores the API base URL. Reference it anywhere with {{baseUrl}}.
Variables reduce duplication and make it easy to switch environments. You can override them per-environment in hitspec.yaml and select one with the --env flag.
2

List all posts (GET collection)

The first request fetches all posts and validates the response shape.
Key concepts:
  • ### separates requests within a file
  • # @name listPosts gives the request an identifier for captures and dependencies
  • # @tags smoke, read lets you filter with --tags smoke
  • The >>> ... <<< block contains assertions
  • expect body type array checks the response is a JSON array
  • expect body[0].id exists checks nested fields using JSON path syntax
3

Get a single post (GET by ID)

This request fetches a specific post and adds a response time assertion.
  • expect body.id == 1 checks an exact value
  • expect body.userId type number validates the JSON type
  • expect duration < 2000 fails if the response takes more than 2 seconds
4

Create a post (POST with JSON body)

This request creates a new resource and captures its ID for later use.
The >>>capture ... <<< block extracts body.id from the response and stores it as newPostId. Later requests reference it as {{createPost.newPostId}} (request name dot capture name).
5

Update the post (PUT with dependency)

This request depends on createPost and uses the captured ID.
# @depends createPost ensures this request runs after createPost completes, even in parallel mode.
6

Delete the post (DELETE)

The final request deletes the resource. It depends on updatePost to preserve execution order.
7

Run the tests

Run all requests:
Run only read operations:
Run only write operations:
Expected output:

Key Concepts Used

Next Steps

Auth Flow

Chain login and authenticated requests with token capture.

Environments

Use different base URLs and variables per environment.
Last modified on June 16, 2026