Skip to main content

How to Send API Requests from a .http File in VS Code and Visual Studio

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

A .http file is a plain text file that holds API requests. It lives next to your code and goes into Git with it, so everyone on the team has the same requests. VS Code with the free REST Client extension and Visual Studio both add a link above each request that sends it. This guide covers the format and how to send requests in each editor.

Prerequisites​

Install the free REST Client extension, by Huachao Mao. Open the Extensions view, search for REST Client, and select Install.

Step 1: Write a Request​

The simplest request is one line, with the method and the address:

src/Dewiride.Inventory.Api/Dewiride.Inventory.Api.http
GET http://localhost:5190/api/v1/categories

Microsoft's page gives the format as HTTPMethod URL HTTPVersion, all on one line, and the version is optional.

Step 2: Send It​

The extension's page says: "click the Send Request link above the request". On macOS, Cmd+Alt+R does the same, and on Windows and Linux Ctrl+Alt+R. The response opens in a new tab beside the file.

The API's answer:

Response
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

[
{
"id": 1,
"name": "Cables",
"createdAtUtc": "2026-11-04T10:48:37.000261Z"
},
{
"id": 2,
"name": "Chargers",
"createdAtUtc": "2026-11-04T10:48:38.457419Z"
}
]

The response shows the status, the headers and the body. The real one also has Date, Server and Transfer-Encoding headers, left out here.

Step 3: Keep Several Requests in One File​

### separates requests. Text after ### on the same line works as a label for the request:

src/Dewiride.Inventory.Api/Dewiride.Inventory.Api.http
### List every category
GET http://localhost:5190/api/v1/categories

### Get one category
GET http://localhost:5190/api/v1/categories/1

Each one gets its own link. The API's /health/live and the rest can all live in the same file.

Step 4: Use a Variable for the Address​

A line that starts with @ defines a variable, and {{name}} uses it. When the port changes, you change one line:

src/Dewiride.Inventory.Api/Dewiride.Inventory.Api.http
@Dewiride.Inventory.Api_HostAddress = http://localhost:5190

### List every category
GET {{Dewiride.Inventory.Api_HostAddress}}/api/v1/categories

dotnet new webapi writes a variable like this into the .http file it creates, named after the project.

Step 5: Send a JSON Body​

A POST or PUT needs a header that says the body is JSON, then a blank line, then the body:

src/Dewiride.Inventory.Api/Dewiride.Inventory.Api.http
### Create a category
POST {{Dewiride.Inventory.Api_HostAddress}}/api/v1/categories
Content-Type: application/json

{
"name": "Cables"
}
Response
HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8
Location: /api/v1/categories/1

{
"id": 1,
"name": "Cables",
"createdAtUtc": "2026-11-04T10:48:37.000261Z"
}

A terminal with the POST request to /api/v1/categories with a JSON body, and the 201 Created response with a Location header and the new category's JSON.

The blank line matters: it's how the format tells headers from the body. Without the Content-Type line, the API answers 415 Unsupported Media Type, as this post shows.

What the Editors Don't Share​

The basic format works in both, because Microsoft's page says Visual Studio's editor "was inspired by the Visual Studio Code REST Client extension". They aren't identical, though: the page says Visual Studio's "doesn't have all the features" of the extension, and lists them. Stick to @variables, ###, headers and bodies, and the same file works in both.

Common Mistakes​

MistakeWhat happensDo this instead
No blank line before the bodyThe body is read as more headersLeave one blank line
No Content-Type on a JSON body415 Unsupported Media TypeAdd Content-Type: application/json
Sending before the API is runningThe request fails to connectStart the API first
Putting real tokens or passwords in the fileThey end up in GitUse environment files, and keep secrets out
No link above the request in VS CodeThe file isn't in HTTP modeCheck the language in the status bar, and that the extension is installed

FAQ​

Is this better than Postman?​

It's different. A .http file is plain text, so it's reviewed and versioned with the code, and it needs no account. Postman does more, such as collections and test scripts.

Can I use a .rest extension?​

Yes. Microsoft's page says the editor "recognizes .rest as an alternative file extension for the same file format."

Does it work outside the editor?​

Not by itself. For scripts, use curl.

Conclusion​

A .http file keeps your API requests in plain text next to the code. Write the method and address on one line, separate requests with ###, put the address in an @variable, and leave a blank line before a JSON body. VS Code needs the REST Client extension, and Visual Studio has it built in, with a Send Request link above each request.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.