

HTTP-REPL Tool to test WEB API in ASP.NET Core 2.2
source link: https://www.tuicool.com/articles/hit/3MrYbef
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Today there are no tools built into Visual Studio to test WEB API. Using browsers, one can only test http GET
requests. You need to use third-party tools like Postman , SoapUI , Fiddler or Swagger to perform a complete testing of the WEB API. In ASP.NET Core 2.2 , a CLI based new dotnet core global tool named “http-repl” is introduced to interact with API endpoints. It’s a CLI based tool which can list down all the routes and execute all HTTP verbs. In this post, let’s find out how to use HTTP-REPL tool to test WEB API in ASP.NET Core 2.2.
HTTP-REPL Tool to test WEB API in ASP.NET Core 2.2
The “http-repl” is a dotnet core global tool and to install this tool, run the following command. At the time of writing this post, the http-repl tool is in preview stage
and available for download at dotnet.myget.org
dotnet tool install -g dotnet-httprepl --version 2.2.0-* --add-source https://dotnet.myget.org/F/dotnet-core/api/v3/index.json
Once installed, you can verify the installation using the following command.
dotnet tool list -g
Now the tool is installed, let’s see how we can test the WEB API. For this tool to work properly, the prerequisite here is that your services will have Swagger/OpenAPI available that describes the service . For this post, I am using the ASP.NET Core WEB API sample code used in this post, which have swagger enabled.
We need to add this tool to web browser list so that we can browse the API with this tool. To do that, follow the steps given in the below image.
The location of HTTP-REPL tool executable is "C:\Users\<username>\.dotnet\tools"
. Once added, you can verify it in the browser list.
Run the app (make sure HTTP REPL is selected in browser list) and you should see a command prompt window. As mentioned earlier, it’s a CLI based experience so you can use commands like dir
, ls
, cd
and cls
. Below is an example run where I start-up a Web API.
You can use all the HTTP Verbs, and when using the POST
verb, you should set a default text editor to supply the JSON. You can set Visual Studio Code as default text editor using the following command.
pref set editor.command.default "C:\Program Files (x86)\Microsoft VS Code\Code.exe"
Once the default editor is set, and you fire POST
verb, it will launch the editor with the JSON written for you. See below GIF.
You can also navigate to the Swagger UI from the command prompt via executing ui
command. Like,
Similarly, you can also execute the DELETE
and PUT
. In case of PUT
command, you should use following syntax and in the default code editor, supply the updated data.
> delete 2 //This would delete the record with id 2. > > put 2010 -h "Content-Type: application/json"
When you fire PUT
command, the behavior is same as the POST
verb. The text editor will open with the JSON written for you, just supply the updated value to execute PUT
command.
Pros and Cons
Pros
- Helps in debugging WEB API
- Fast and quickly switch between API endpoints
- Descriptive error response shown
Cons:
- Dependency on Swagger/Open API specification
- Not as informative as UI tools
After playing with this for a while, I strongly feel it’s command line version of the Swagger UI and it would be very handy when there are many API endpoints. You can easily navigate or switch between the APIs and execute it.
Summary
Nowadays, many tools are going towards CLI experience and http-repl is another addition to the list. This tool allows you to test WEB API endpoints supporting all HTTP verbs. You can quickly navigate between the APIs and test them. I am not sure about the future of this tool and whether the community and developers will adopt this new tool as it’s a CLI version of Swagger.
Thank you for reading. Keep visiting this blog and share this in your network. Please put your thoughts and feedback in the comments section.
PS: At the time of writing this post, The http-repl tool is still in preview stage and the experience may change.
PS:If you found this content valuable and want to return the favour, then
Recommend
-
10
The purpose of this post is to walk through the basics of starting an ASP.NET Core HTTP API. A fundamental understanding of all the parts that make an ASP.NET Core HTTP API work and why each element matters. We’ll also explore writing an exte...
-
8
We have all been doing “web services” forever. My first introduction was in the late 90’s with XML-RPC and WDDX. Followed up soon after with SOAP. Good times. Oh and remember WS-*. Don’t remind me.Over the last couple years,...
-
11
0:00 / 1:15:25 ...
-
6
Xamarin REPL (read-eval-print-loop) is one of the most important tools for building Xamarin.UITest tests. It’s a console-like environment in which we can see the structure of the visible part of our application using queries and commands. It...
-
12
Exploring a minimal Web API with ASP.NET Core 6 Sponsored By I write about
-
9
Hey, developer folks...
-
8
Test run of HTTP Logging in ASP.NET Core 6 Written by Thomas Ardal, December 06, 2021 Ever wanted to log all HTTP requests to your websites? I sure have a...
-
8
November 19, 2020 Versioning for ASP.NET Core Web API .NET Few days ago, me and my friends were developing an API using ASP.NET Core...
-
12
-
6
[JavaScript] Test Text-to-Speech in Web Speech API April 22, 2017
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK