using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
namespace BookStore.Controllers
public class BooksController : ControllerBase
private static List<Book> books = new List<Book>
new Book { Id = 1, Title = "1984", Author = "George Orwell" },
new Book { Id = 2, Title = "To Kill a Mockingbird", Author = "Harper Lee" }
public ActionResult<IEnumerable<Book>> Get()
public ActionResult<Book> Get(int id)
var book = books.FirstOrDefault(b => b.Id == id);
public IActionResult Post([FromBody] Book book)
return CreatedAtAction(nameof(Get), new { id = book.Id }, book);
public IActionResult Put(int id, [FromBody] Book book)
var index = books.FindIndex(b => b.Id == id);
public IActionResult Delete(int id)
var index = books.FindIndex(b => b.Id == id);
public int Id { get; set; }
public string Title { get; set; }
public string Author { get; set; }