Skip to content

Week 1–2: Minimal APIs Basics

Build a Books API with in-memory storage. Learn how Minimal APIs work, how to create endpoints, and how to test them with Swagger.

Core skills:

  • Create a Minimal API project with dotnet new web
  • Make GET and POST endpoints
  • Use route parameters (/books/{id})
  • Return proper status codes using the Results helper
  • Test with Swagger UI

“Show me how to create a .NET 8 Minimal API with a GET endpoint that returns a list of books. Books have Id, Title, Author, Year. Use an in-memory List.”

“Add POST, PUT, DELETE endpoints for books. Use Results.Ok(), Results.Created(), Results.NotFound() for proper status codes.”

“Explain when to use Results.Ok() vs Results.Created() vs Results.NotFound(). Simple examples please.”

  • Understanding Program.cs structure
  • Query parameters (?search=value)
  • .http files for testing
  • Dependency injection details

Build a Books API with in-memory storage using a List<Book>.

  1. Run dotnet new web -n BooksApi and explore the generated files
  2. Add a Book class with Id, Title, Author, Year
  3. Create GET /books — returns all books
  4. Create GET /books/{id} — returns one book or 404
  5. Create POST /books — adds to list, returns 201
  6. Create PUT /books/{id} — updates book, returns 204 or 404
  7. Create DELETE /books/{id} — removes book, returns 204 or 404
  8. Open Swagger and manually test every endpoint
  • app.MapGet(), app.MapPost(), app.MapPut(), app.MapDelete() syntax
  • Route parameters vs query parameters
  • Results.Ok(), Results.Created(), Results.NotFound(), Results.BadRequest()
  • Running and testing locally with Swagger

Books API with in-memory List, all CRUD endpoints working in Swagger.


Setup | Back to Overview | Week 3–4: PostgreSQL