From the course: Learning ASP.NET Core: MVC, Razor Pages, Web APIs & Other Foundations

Unlock this course with a free trial

Join today to access over 24,600 courses taught by industry experts.

Challenge: Create a Web API

Challenge: Create a Web API

(playful music) - [Instructor] It's your turn to practice creating your own web API. In this challenge, I want you to start by creating a new minimal Web API project using the .NET CLI. As you've seen, the project template includes sample code related to weather forecasts. Go ahead and remove the code specific to serving weather data. We're going to serve book data in this API. Add a new "Book" record type to the program.CS file that includes string properties for the book's title and author. This will be our model type. If this were a production application, you would probably retrieve actual book data from a database of some kind, but since we don't have that here, create several new book instances and add them to an array and store the array in a variable. We'll use that as our tiny data source. Next, create a new API endpoint to return all the books in the array. Choose any URL that makes sense to you for that purpose. Create a second endpoint to allow callers of your API to…

Contents