How to install and use httprepl(New Feature in ASP.NET Core 2.2)?
So, what we are doing in ASP.NET Core 2.2 is there is a new tool which name is “httprepl”. It’s a dotnet core global tool that you can install in your machine and that gives you a command line repl for interacting with API endpoints. Let’s install it from the command line:
dotnet tool install -g --version 2.2.0-* --add-source https://dotnet.myget.org/F/dotnet-core/api/v3/index.json dotnet-httprepl
If you have already installed then, you can verify it with the following command:
dotnet tool list -g
You can see that “httprepl” was installed on my machine.
All right, now I should be able to do “dotnet htttprepl” then it will pop me into the interactive repl. This repl helps me to interact with API endpoints.
Right now, it’s disconnected cause It is not connected to any thing.so we can use this repl to interact with either asp.net core API’s or any other API that we want, for example, let's point out to GitHub API by applying the following command:
set base https://api.github.com
After connected. I run the help text just to see what this thing can do.
You can see I can issue any http requests for any http method I can set headers. It looks like it has information it knows how to deal with swagger documents. So, if you have an API that has an open API spec or a swagger document the tool can light up additional functionality. For example, it allows you to traverse of navigate URI space of your API using a file system like commands (ls, cd).so that’s pretty cool and then there’s also a capability to run scripts like if you want to set up a bunch of repl commands that you just run as a batch. You can run them all together by just creating a file.
Let’s try just sending get a request to GitHub API
Here we can see the response with bunches of links that I can use to then traverse to other resources that are available through API. For example, emojis URL, Let’s run the following command:
get emojis
Here we can see a list of our links to every single emoji, that GitHub supports and there are apparently quite a few of those and let’s pick a link of an ambulance (https://assets-cdn.github.com/images/icons/emoji/unicode/1f691.png) and check on the browser
That’s pretty cool. Likewise, we can point it to Web API as well.