/learn-aspnetcore

Learn to create a web API with ASP.NET Core

Primary LanguageC#

learn-aspnetcore

Learn to create a web API with ASP.NET Core based this tutorial.

Test Run Locally

  1. Ctrl + F5 or go to Menu -> Run -> Run Without Debugging

  2. The browser should be automatically opened. Otherwise, grab the server URL and post from the debug console log.

  3. Open the Swagger page at path /swagger.

  4. 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 
    
  5. 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
    }
  6. Add another TodoItem with POST and test the GET /api/TodoItems.

  7. Test the PUT /api/TodoItems/{id} by getting an item and update the data in the PUT request body.

  8. Test the DELETE /api/TodoItems/{id} on an existing item.

Note: You can also use Postman, curl, or httprepl to test the APIs.