You are here
Home > Programming > Accelerate API Development in Visual Studio with .http/.rest Files!

Accelerate API Development in Visual Studio with .http/.rest Files!

Accelerate API Development with http or rest files in Visual Studio

Accelerate API Development – Modern web applications rely heavily on back-end APIs and microservices, which can be challenging to develop efficiently due to the need for agility and quick iterations. To make working with APIs easier during the entire inner-loop lifecycle, from coding to testing, Visual Studio has introduced a new feature in ASP.NET Core Projects: .http/.rest files and an integrated HTTP client. These files provide concise definitions for API endpoints and enable you to run your APIs and modify various REST calls to see structured outputs within Visual Studio.

Not quite what you were looking for? Try these links instead.

Accelerate API Development

It’s important to note that .http/.rest files do not replace integration and unit testing but provide an alternative way to iterate rapidly during API development while monitoring the APIs used by your app and investigating inputs and outputs. This is just the beginning of the Visual Studio team’s efforts to improve the quality of life for C# .NET developers working with microservices in Visual Studio. You can count on them sharing more features in upcoming previews. To use this feature, ensure that you have Visual Studio 17.5 installed. I have created a simple Books API, that manages my book library. The controller is illustrated in the image below.

The book API Controller

Debugging the API would require the use of Swagger, Postman, or other similar tool. With Visual Studio 17.5, however, you can debug your API directly inside of Visual Studio with the use of .http/.rest files. In the screenshot below, you will notice that I have added a Playground folder, and inside of that, I have added an HTTP file called books.http.

The books.http file added to Visual Studio

Inside of this file, I can add my API calls as seen in the code below.

I can add the GET, POST, PUT, and DELETE requests inside of this file. Once this is done, a green play button will appear next to each URL. I can then run them and see the results inside of Visual Studio.

Running my API queries inside of Visual Studio

The results are output in a new window and allows me to inspect the results. It is important to note that I can use variables as seen at the top of the .http file. I can then plug these into the URL by using the double curly braces.

This new feature in Visual Studio allows developers to accelerate API development and allows for a smoother inner-loop lifecycle.

Dirk Strauss
Dirk is a Software Developer from South Africa. He loves all things Technology and is slightly addicted to Jimi Hendrix. Apart from writing code, he also enjoys authoring books and articles. "I love sharing knowledge and connecting with people from around the world. It's the diversity that makes life so beautiful." Dirk feels very strongly that pizza is simply not complete without Tabasco, that you can never have too much garlic, and that cooking the perfect steak is an art he has almost mastered.

Similar Articles