This project is a small ASP.NET Core minimal API sample for blog posts and comments. A single entry point, small DTOs, one service interface, and two storage implementations.
- The API uses the in-memory service by default.
- The same API can also run against SQL Server by switching one configuration value. Instruction below.
- The browser UI in
wwwrootexists only to provide demonstration of API from a simple page. - Sample seed data is included in both service implementations so the app has content on first run.
- List blog posts
- View a single post with comments
- Create, update, and delete posts
- Add comments to a post
- Switch between
InMemorystorage andSqlServerstorage in appsettings
Program.cs: application startup, configuration, validation helpers, and route mappingContracts/BlogDtos.cs: request and response records used by the APIModels/: simple in-memory model classesServices/IBlogService.cs: shared contract for both storage implementationsServices/InMemoryBlogService.cs: easiest implementation to read and runServices/SqlBlogService.cs: SQL Server implementation usingMicrosoft.Data.SqlClientDatabase/init.sql: creates the SQL database and tableswwwroot/: small HTML, CSS, and JavaScript client for manual testingBlogApp.http: ready-made HTTP requests for quick endpoint checks
GET /posts: list postsGET /posts/{id}: get one post with commentsPOST /posts: create a postPUT /posts/{id}: update a postDELETE /posts/{id}: delete a postGET /posts/{id}/comments: list comments for a postPOST /posts/{id}/comments: add a comment
- Run
dotnet run. - Open
http://localhost:5030for the demo UI or useBlogApp.httpfor direct API calls.
No database setup is required for this path.
- Run
Database/init.sqlagainst SQL Server. - Set
Persistence:ProvidertoSqlServer. - Update
ConnectionStrings:BlogDatabasewith a real connection string. - Run
dotnet run.