(ASPNET Core Exercises) Practice Exercises on Web Api in ASPNET Core

This is a collection of exercises on Web Api in ASPNET Core. Solutions have been provided for almost all of them.
(Rev. 31-Oct-2024)

Categories | About |     |  

Parveen,

Table of Contents (top down ↓)

Exercise 1 - Create an ASPNET Core project and use AddSingleton function to add a collection (List<string>) of a few strings to the services container. Add a GET Web Api (/api/all) that returns the entire collection of strings. Test with curl OR your browser.

Solution ⟹ Please refer this →

The above link leads to our course on ASPNET Core Solution + Projects + Exercises + Tutorials + Interview Questions please visit the link.

Exercise 2 - Create an ASPNET Core project and use AddSingleton function to add a collection (List<string>) of these strings - "apple", "TV", "grapes", "USA" to the services container. Add a GET Web Api (/api/items/{index}) that returns the item at the required index, in an HTTP OK response. The api should return HTTP NotFound if the index is < 0, or > 3. Test with curl.

Solution ⟹ Please refer this →

The above link leads to our course on ASPNET Core Solution + Projects + Exercises + Tutorials + Interview Questions please visit the link.

Exercise 3 - Create an ASPNET Core project and add a class called Product with two properties int: ID and string: Name. To avoid creating a database, use AddSingleton function to add a collection (List<Product>) to the services container. Your project should expose a GET Web Api (/api/items) that returns all the items. Next add a POST Web Api (/api/items) to add an item to the collection. Test with curl thus: (1) Call GET WebApi, (2) Call POST WebApi and (3) Call GET WebApi.

Solution ⟹ Please refer this →

The above link leads to our course on ASPNET Core Solution + Projects + Exercises + Tutorials + Interview Questions please visit the link.

Exercise 4 - Create an ASPNET Core project and add a class called Product with two properties int: ID and string: Name. To avoid creating a database, use AddSingleton function to add a collection (List<Product>) to the services container. Your project should expose a GET Web Api (/api/items) that returns all the items. Next add a PUT Web Api (/api/items/{id}) to update an item of the collection. Test with curl thus: (1) Call GET WebApi, (2) Call PUT WebApi and (3) Call GET WebApi.

Solution ⟹ Please refer this →

The above link leads to our course on ASPNET Core Solution + Projects + Exercises + Tutorials + Interview Questions please visit the link.


This Blog Post/Article "(ASPNET Core Exercises) Practice Exercises on Web Api in ASPNET Core" by Parveen is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.