Create a minimal API with ASP.NET Core – Part 3
1 min read

Create a minimal API with ASP.NET Core – Part 3

Alright! Let´s examine our new api. Remember to restart our app before continuing since you updated our code last time.

In the tutorial we use postman but we can also use invoke-webrequest that is built in to powershell.

Create a variable containing a formated string as json. This contains a name and the bool for isComplete. Next we invoke a webrequest with the method Post using the variable as body.

$body_json = '{ "name": "do awesome thing 1", "isComplete":true } '  
Invoke-WebRequest -Uri http://localhost:5080/todoitems -Method Post -Body $body_json -ContentType "application/json"

And our webapp returns 201 created so we should have this now in our in memory database. Let´s use a different endpoint and try and collect all current todos.

Invoke-WebRequest -Uri http://localhost:5080/todoitems -Method Get

Let´s write another entry to our database so we can see how it looks like when there is more than one. Just repeat the last part and update the variable with 2 instead in the json string.

Use the GET enpoint again and check to see if you have more content returned from the database. And sure you do!

As our last test let´s try and get just one database entry with another endpoint.

Invoke-WebRequest -Uri http://localhost:5080/todoitems/1 -Method Get

There you go! You can also use PUT to update an entry or delete to remove it. This you can test on your own.

Great work! You just made your very own API! Great work!