How to use Postman in an ASP. NET Core Web API test

Source: Internet
Author: User

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.

    1. Download and run the following todomvcsolution from this link.

    1. 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.

  1. Copyright (c) smartit. All rights reserved.

  2. by John Kocer

  3. This file was for the Swagger test, this application does not the use the This file

  4. Using System.Collections.Generic;

  5. Using MICROSOFT.ASPNETCORE.MVC;

  6. Using SmartIT.Employee.MockDB;

  7. Namespace TodoAngular.Ui.Controllers

  8. {

  9. [Produces ("Application/json")]

  10. [Route ("Api/todo")]

  11. Publicclass Todoapicontroller:controller

  12. {

  13. Todorepository _todorepository = new Todorepository ();

  14. [Route ("~/api/getalltodos")]

  15. [HttpGet]

  16. Public ienumerable<smartit.employee.mockdb.todo> Getalltodos ()

  17. {

  18. return _todorepository.getall ();

  19. }

  20. [Route ("~/api/addtodo")]

  21. [HttpPost]

  22. Public SmartIT.Employee.MockDB.Todo Addtodo ([Frombody]smartit.employee.mockdb.todo Item)

  23. {

  24. return _todorepository.add (item);

  25. }

  26. [Route ("~/api/updatetodo")]

  27. [Httpput]

  28. Public SmartIT.Employee.MockDB.Todo Updatetodo ([Frombody]smartit.employee.mockdb.todo Item)

  29. {

  30. return _todorepository.update (item);

  31. }

  32. [Route ("~/api/deletetodo/{id}")]

  33. [Httpdelete]

  34. Publicvoid Delete (int id)

  35. {

  36. var Findtodo = _todorepository.findbyid (ID);

  37. if (Findtodo! = null)

  38. _todorepository.delete (Findtodo);

  39. }

  40. }

  41. }

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.