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.
- Xcode Stuck on Updating or Installing on M1 MacBook Pro
- Code Optimization using Span : An Introduction
- Required Properties in C# 11
- Static Abstract Interface Members in C#11
- Rainbow Braces for Visual Studio: A Comprehensive Guide
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.
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.
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.
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.