Learn to create a web API with ASP.NET Core based this tutorial.
-
Ctrl + F5 or go to Menu -> Run -> Run Without Debugging
-
The browser should be automatically opened. Otherwise, grab the server URL and post from the debug console log.
-
Open the Swagger page at path
/swagger
. -
Test the POST
/api/TodoItems
API with the following body:{ "name": "walk dog", "isComplete": true }
You should get the following similar response:
{ "id": 1, "name": "walk dog", "isComplete": true }
The response's
location
header should point to the newly-created TodoItem:content-type: application/json; charset=utf-8 date: Sun,20 Nov 2022 08:35:35 GMT location: http://localhost:5206/api/TodoItems/1 server: Kestrel transfer-encoding: chunked
-
Test the GET
/api/TodoItems/{id}
API for the new TodoItem an you should get the same response:{ "id": 1, "name": "walk dog", "isComplete": true }
-
Add another TodoItem with POST and test the GET
/api/TodoItems
. -
Test the PUT
/api/TodoItems/{id}
by getting an item and update the data in the PUT request body. -
Test the DELETE
/api/TodoItems/{id}
on an existing item.
Note: You can also use Postman, curl, or httprepl to test the APIs.