Intro
As a .NET developer, you've likely relied on tools like Postman, curl, or Swagger UI to test your APIs. But what if you could test your API directly inside your IDE — without switching context?
That's where .http
files come in. Supported by Visual Studio, JetBrains Rider, and VS Code (with extensions), these simple text files allow you to write and execute HTTP requests directly inside your project.
Let’s explore how to integrate .http
files into a .NET 8 Web API project with real examples, environment configs, and some handy tips.
What is a .http
file?
A .http
file is a plain text file where you define HTTP requests (GET, POST, PUT, DELETE, etc.) in a human-readable way.
Example
`### Get all usersGET https://localhost:5001/api/usersAccept: application/json###POST https://localhost:5001/api/usersContent-Type: application/json{ "name": "Jane Doe", "email": "jane@example.com"}`
You can run these requests without opening a browser or Postman. Just click a button in your IDE. Bliss.
Setting Up in a .NET 8 Project
Let’s walk through how to use .http
files in a .NET 8 Web API project.
1. Create a New .NET 8 Web API Project
`dotnet new webapi -n HttpFileDemo cd HttpFileDemo``dotnet run`
Your default API should be running on something like https://localhost:5001
.
2. Add a .http
File
In the root of the project (or in a folder like Tests
), add a new file:
requests.http
Add the following content:
`### Ping APIGET https://localhost:5001/weatherforecastAccept: application/json`
In Visual Studio, click the green "Send Request" button that appears next to the line.
In Rider, hit the Play icon beside the request.
Working with Variables and Environments
For DRY and reusable testing, you can define variables.
Example:
`@host = https://localhost:5001
Get Weather
GET {{host}}/weatherforecastAccept: application/json`
3. Creating Environment Files
To manage multiple environments (dev, staging, prod), create:
http-client.env.json
in your project root:
`{ "Local": { "host": "https://localhost:5001" }, "Staging": { "host": "https://staging.myapi.com" }, "Production": { "host": "https://api.myapp.com" } }`
Then in your .http
file:
GET {{host}}/weatherforecast
Switch environments from the dropdown in your IDE.
Sending Auth Tokens
Need to test secured APIs? You can pass bearer tokens easily.
`GET {{host}}/secure-endpointAuthorization: Bearer {{access_token}}`
You can hardcode or use a variable for access_token
.
Testing POST, PUT, DELETE
POST Example
`POST {{host}}/api/usersContent-Type: application/json{ "name": "Sam", "email": "sam@domain.com"}`
PUT Example
`PUT {{host}}/api/users/1Content-Type: application/json{ "name": "Updated Name"}`
DELETE Example
`DELETE {{host}}/api/users/1`
Example in a Full .NET 8 Controller
UsersController.cs
[ApiController][Route("api/[controller]")] public class UsersController : ControllerBase { private static List<User> users = new(); [HttpGet] public IActionResult Get() => Ok(users); [HttpPost] public IActionResult Create(User user) { user.Id = Guid.NewGuid(); users.Add(user); return CreatedAtAction(nameof(Get), new { id = user.Id }, user); } [HttpDelete("{id}")] public IActionResult Delete(Guid id) { var user = users.FirstOrDefault(u => u.Id == id); if (user == null) return NotFound(); users.Remove(user); return NoContent(); } }public class User{public Guid Id { get; set; }public string Name { get; set; }public string Email { get; set; }}
`
requests.http
`@host = https://localhost:5001### Get all usersGET {{host}}/api/users###POST {{host}}/api/usersContent-Type: application/json{ "name": "Jane", "email": "jane@example.com"}###DELETE {{host}}/api/users/{{userId}}`
Tips & Tricks
Separates requests.
###
Declare variables.
@var = value
Use variables.
{{var}}
Manage environments.
http-client.env.json
Shortcut to run request.
ALT+Enter
/ Ctrl+Enter
Comments
Use #
or //
for notes.
Limitations
→ No built-in test assertion logic (like Postman tests).
→ IDE-dependent behavior may vary (VS vs Rider vs VS Code).
→ Doesn't simulate a real frontend request (cookies, UI, etc.).
When Should You Use .http
Files?
→ During development, for quick test loops.
→ As lightweight test documentation.
→ As part of API documentation for teammates.
→ For local, integration, or smoke testing.
Should You Commit .http
Files?
Yes — if:
→ They’re not storing sensitive credentials.
→ You want them as documentation or team-shared test files.
No — if:
→ They contain hardcoded secrets or tokens.
→ They're temporary scratchpad files.
To Conclude
.http
files in a .NET 8 project are a game-changer for developers who want quick, readable, testable HTTP requests without leaving their IDE. Think of it as "Postman in your code editor" — only faster and more integrated.
Whether you’re testing a new endpoint or documenting workflows for your team, .http
files will streamline your process like never before.
Further Steps
Add
.http
files to your current .NET 8 project.Organize them by feature or controller (
users.http
,auth.http
).Use
http-client.env.json
to manage different environments.Explore token injection or pre-request scripting with extensions in VS Code or Rider.
Join me on Patreon for more helpful tips. Make sure to like and Follow to stay in the loop with my latest articles on different topics including programming tips & tricks, tools, Framework, Latest Technologies updates.
Support me on Patreon
I would love to see you in the followers list.