The Web Api that we have to call
Open the WebApi project that we have been discussing in this chapter. This project is already available in your downloads. Locate the program.cs file and scroll to the part that you are seeing here.
// GET WebApi from Program.cs // the webapi project is in your downloads app.MapGet("/doctor/all", async (MyApiContext ctx) => { return await ctx.Doctors...ToListAsync(); } );
We shall make a call to this GET web api. It responds with a json of all the records. Also, recall that, as we explained in the previous tutorial, the endpoint of our web api is "doctor" because it appears as the first segment of the route templates of all our web api.
Run the project to open the home page. This ensures that the server is up and running. Take note of the address - it will be required for making a connection between httprepl and this server.
Video Explanation (see it happen!)
Please watch the following youtube video:
Connect http repl
Next, we have to make a connection between http repl and our web api server. Come to visual studio and use the menu Tools > Command Line > Developer Command Prompt and open the http repl console window. Type the command httprepl followed by the server address as you are seeing here. Hit enter and wait for the connection.
If everything goes right, the command prompt will now show the address of your server as you are seeing here.
https://localhost:7264/>
Next we have to connect to the "doctor" endpoint - so type the command cd doctor and hit enter.
cd doctor
If everything goes right, then you should now be connected to the "doctor" endpoint, as you are seeing here.
https://localhost:7264/doctor>
Making the Call
Now we can execute the call to our api. The route template to our GET api is doctor/all.
At the command prompt type GET all as you are seeing here.
https://localhost:7264/doctor> GET all
Hit enter, and wait for the response from the server. We verify that we have received a json of all the records - as expected.
HTTP/1.1 200 OK Content-Type: application/json; charset=utf-8 Date: Fri, 03 Jun 2022 06:32:12 GMT Server: Kestrel Transfer-Encoding: chunked [ { "id": 1, "name": "doc 1", "fees": 100 }, { "id": 2, "name": "doc 2", "fees": 200 } ]
In the next tutorial we shall execute the POST api.
Similar Posts
This Blog Post/Article "(C# ASP.NET Core) Testing a GET Web Api with HttpRepl" by Parveen is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.