AspireDotNet

Sending requests to API endpoints with .http files

Author: Areg Sarkissian

Introduction

In this post we will see two ways that we can send adhoc requests to an API that we are developing.

First we will see how to use .http files to send requests to our APIs.

These files can contain a collection of requests that can be saved to source control for later reuse.

We will also show an example of sending requests using the Curl command line utility.

This post uses .NET 11

Editor support for .http files

Make sure your editor is configured to support .http files.

Some editors like Visual Studio or Rider have built in support for .http files. VSCode editor needs the REST Client for Visual Studio Code extension.

For this post I will be using VSCode with the REST Client extension.

Pre-requisites

Perform steps for creating the Contacts Minimal API solution we created in the https://aspiredotnet.bearblog.dev/minimal_apis/ post.

Make sure you are in the Contacts solution root directory that contains the Contacts.slnx file:

All following dotnet cli commands are executed from the root directory of the solution.

Adding the .http file to the project

Now that we have a project to work with let's add the .http file:

touch src/Contacts.Api/Hello.http

Open the file and a HTTP GET request to the root / URL:

@baseUrl = http://localhost:5095

### Get Root URL
GET {{baseUrl}}/
Accept: text/plain

Replace the @baseUrl port number with the randomly generated port number of the applicationUrl setting in the http profile of your projects Properties/launchSettings.json file.

Sending requests with the .http file

Run the the project with the http profile:

dotnet run --project src/Contacts.Api/Contacts.Api.csproj --launch-profile http

Click on the send request button right below the comment line in the .http file to send the GET request to the root URL.

The response should look like:

HTTP/1.1 200 OK
Connection: close
Content-Type: text/plain; charset=utf-8
Date: Mon, 16 Nov 2026 18:19:04 GMT
Server: Kestrel
Transfer-Encoding: chunked

Hello World!

.http file example requests

Below I am showing an example .http file that has examples for all the REST http verbs and also has request examples with body content.

It also shows how you can send bearer auth tokens using the Authorization header.

dotnet cli has command for generating local auth tokens.

@baseUrl = https://example.com
@authToken = Bearer replace_with_access_token


### Get a list of resources
GET {{baseUrl}}/users
Authorization: {{authToken}}
Accept: application/json

### Get a resource
GET {{baseUrl}}/users/1
Authorization: {{authToken}}
Accept: application/json

### Post a new resource
POST {{baseUrl}}/users
Authorization: {{authToken}}
Content-Type: application/json

{
    "name": "Areg Sarkissian",
    "email": "areg.sarkissina@example.com"
}

### Put an existing resource entirely
PUT {{baseUrl}}/users/1
Authorization: {{authToken}}
Content-Type: application/json

{
    "name": "Areg Sarkissian",
    "email": "areg.sarkissina@example.com"
}

### Patch an existing resource
PATCH {{baseUrl}}/users/1
Authorization: {{authToken}}
Content-Type: application/json

{
    "email": "areg.sarkissian@example.com"
}

### Delete a resource
DELETE {{baseUrl}}/users/1
Authorization: {{authToken}}

Using Curl cli to send requests to the api

If you have curl utility installed you can also send a requests using the curl cli.

Open another terminal tab and run the curl command:

curl -i -H "Connection: close" http://localhost:5095

Be sure to change the port number according to the http profile of your projects Properties/launchSettings.json file.

Note that with Curl we need to explicitly send the Connection: close header for the Kestrel server to close the connection using. This is something that the VSCode REST Client extension takes care of automatically when we use the .http file to make the request. The HTTP Client extension automatically injects the Connection: close header into the request which is why we get the Connection: close header back in the response when using the .http file to send the request.

You should see the same response as we saw when we used the .http file to make the request to the root URL.

HTTP/1.1 200 OK
Connection: close
Content-Type: text/plain; charset=utf-8
Date: Mon, 16 Nov 2026 18:20:43 GMT
Server: Kestrel
Transfer-Encoding: chunked

Hello World!

Conclusion

In this post we saw how to use .http files for sending adhoc api request to our minimal api endpoints.

These .http files are very convenient to use and can be saved to your repository along with your projects so all team members can use them.

We also saw you can send requests to your api using the curl command line utility.