Skip to main content
The .http file format lets you define HTTP requests in a readable text format. Breakdance’s DotHttp library provides a runtime and source generator to execute these files as unit tests, with full support for variables, environments, and request chaining.

Prerequisites

1

Install the package

Add the Breakdance DotHttp package to your test project:
2

Create a .http file

Add a .http file to your project. Visual Studio and VS Code provide syntax highlighting.

Quick Start

Create a test class that inherits from DotHttpTestBase:
ApiTests.cs
While you can manually construct DotHttpRequest objects, the real power comes from parsing .http files or using the source generator to create tests automatically.

The .http File Format

A .http file contains one or more HTTP requests separated by ###:
api.http
Each request section includes:
  • An optional comment line starting with # or //
  • The HTTP method and URL
  • Optional headers (key: value format)
  • A blank line separating headers from body
  • An optional request body

Variables

Variables make your requests dynamic and reusable.

Defining Variables

Define variables at the top of your .http file using @variable = value:

Setting Variables in Code

Dynamic Variables

Breakdance supports dynamic variables that generate values at runtime:

DateTime Formatting and Offsets

Dynamic datetime variables support formatting and offsets:
Offset units: ms (milliseconds), s (seconds), m (minutes), h (hours), d (days), w (weeks), M (months), y (years)

Environment Files

Store environment-specific variables in http-client.env.json:
http-client.env.json
Load environments in your tests:

User Overrides

Keep secrets out of source control with .user files:
http-client.env.json.user
Add *.user files to your .gitignore to prevent committing secrets.

Request Chaining

Chain requests together by capturing responses and referencing them in subsequent requests.

Naming Requests

Use # @name to give a request a name for later reference:

Response Reference Syntax

JSONPath Examples

Chaining in Code

Smart Assertions

Go beyond simple status code checking with DotHttpAssertions:

Error Pattern Detection

AssertNoErrorsInBodyAsync catches common API anti-patterns where an error is returned with a 200 status:
Detected patterns:
  • "error": or "errors": fields
  • "success":false or "status":"error"
  • XML <error> elements
  • "fault": fields

Using with Response Caching

Combine DotHttp testing with cached responses for deterministic tests:
See the Response Caching guide for details on capturing and serving cached responses.

Parsing .http Files

Use DotHttpFileParser to parse existing .http files:

Response Caching

Capture and replay HTTP responses for deterministic tests

In-Memory Web API

Test ASP.NET Web API controllers without a server