Use Postman for manual testing
If you are a developer, tester, or manager, it is sometimes a challenge to understand the various API approaches when building and using applications.
Using postman with. NET core to generate good documentation and help pages for your Web API is as simple as making some HTTP calls.
Let's start by downloading simple todo items from GitHub.
Download and run the following todomvcsolution from this link.
Download postman
Postman is a Google Chrome app for testing API calls. You can download and install postman from the website below.
Here is the API we can test-get, publish, place and delete this application.
Here is the Web API we want to test.
Copyright (c) smartit. All rights reserved.
by John Kocer
This file was for the Swagger test, this application does not the use the This file
Using System.Collections.Generic;
Using MICROSOFT.ASPNETCORE.MVC;
Using SmartIT.Employee.MockDB;
Namespace TodoAngular.Ui.Controllers
{
[Produces ("Application/json")]
[Route ("Api/todo")]
Publicclass Todoapicontroller:controller
{
Todorepository _todorepository = new Todorepository ();
[Route ("~/api/getalltodos")]
[HttpGet]
Public ienumerable<smartit.employee.mockdb.todo> Getalltodos ()
{
return _todorepository.getall ();
}
[Route ("~/api/addtodo")]
[HttpPost]
Public SmartIT.Employee.MockDB.Todo Addtodo ([Frombody]smartit.employee.mockdb.todo Item)
{
return _todorepository.add (item);
}
[Route ("~/api/updatetodo")]
[Httpput]
Public SmartIT.Employee.MockDB.Todo Updatetodo ([Frombody]smartit.employee.mockdb.todo Item)
{
return _todorepository.update (item);
}
[Route ("~/api/deletetodo/{id}")]
[Httpdelete]
Publicvoid Delete (int id)
{
var Findtodo = _todorepository.findbyid (ID);
if (Findtodo! = null)
_todorepository.delete (Findtodo);
}
}
}
Note-Your local port number may be different from mine. Use your local port number.
HTTP/localhost:63274/api/getalltodos//GET
HTTP/localhost:63274/api/addtodo//POST
HTTP/localhost:63274/api/updatetodo//PUT
HTTP/LOCALHOST:63274/API/DELETETODO/5//DELETE
Test get with the postman
Testing get is very simple. First, we need to set the HTTP action to get from the drop-down list.
Then, we need to enter or paste into the API URL box.
Then, click the Blue Send button.
If get succeeds, we see the status: OK. Test post with a postman
First, we need to set the HTTP action in the drop-down list to post.
Then, we need to enter or paste into the API URL box.
The Addtodo API accepts JSON-formatted TODO objects. We need to pass a new todo JSON data.
To pass JSON data, we need to select Body Tap.
Select Original
Select JSON (application/JSON) as the text format.
Write or paste your todo json data.
Then, click the Blue Send button.
If the post is successful, we see the status: $ OK.
You will see the status: 200 success, return value from the Returned Values tab. We sent the publish Postman TODO item with id = 0, and we received the ID = 5. Test put with a postman
First, we need to set the HTTP action to put from the drop-down list.
Then, we need to enter or paste into the API URL.
The Updatetodo API accepts JSON-formatted TODO objects. We need to pass an existing TODO JSON data.
To pass the JSON data, we need to select the Positive tab
Select original format
Select JSON (application/JSON) as the text format.
Write or paste your todo JSON
Then click on the Blue Send
If the put is successful, we see the status: OK.
You will see the status: 200 success, return the return value in the Body label. We send out the postman to-do item with "name": "Release the Postman in Progress" and we receive updated backlog results. Test Delete with Postman
First, we need to set the HTTP action to delete from the drop-down list.
Then, we need to enter or paste into the API URL box.
DELETETODO/5 API accepts an ID we need to pass an ID value to an existing TODO.
Then, click the Blue Send button.
If the deletion succeeds, we see the status: $ OK. This will complete the 1th part of the Postman tutorial. In "The second part uses the postman for automated testing", we will examine the Postman API Automation test and write a script to run the continuous integration test case.
Profile
In this article, we learned how to use postman with the ASP. NET Core Web API.
This article turns from: https://www.toutiao.com/i6489186032729195021/, if you need to reprint, please indicate the source.
How to use Postman in an ASP. NET Core Web API test