This is a bookstore or just a book api written in c# using asp.net core 6 core. THe goal of this project was to make an api, that returns books to anyone who calls it. It's also designed to be somewhat resistant to XSS attacks and has some rudimentary unit tests.
Most notable packages one should know:
-asp.net 6 core
-runs on port 9000 (http) and 9001 (https)
-https://localhost:9001/books/
-http://localhost:9000/books/
-c#
-AspNetCore.Identity.EntityFrameworkCore
-Microsoft.EntityFrameworkCore.Sqlite
-Microsoft.EntityFrameworkCore.Tools
-Newtonsoft
-HtmlSanitizer
Clone the repository normally. After the cloning process is done, make sure that Books.db exists in the same folder as BookStoreAPI.
Database is hosted on Sqlite (in the file Books.db). So, make sure you have the file before booting the project. Make sure to run the following command on Package Manager Console:
update-database
or you might have to
drop-database
The database will be set up during that process.
Starting from the top, we have controllers, that contains BooksController, which is reponsible for getting data.
Data folder contains datacontext and db migration files.
Middleware contains errorhandling and anti-Xss middleware.
Models houses three datamodels, Book, HttpResponseException, and PostRequestResponseMessage.
Utilities consists of two utility classes, HttpResponseUtilities and QueryUtilities. HttpResponseUtilities is used for throwing exceptions and AueryUtilities is used for depositing functions from BooksController to make it cleaner.
After setting up the database, the initial startup will give you the swagger page.
Responses containing books are sent back in Json.
Things to know about .Tests:
-asp.net 6 core
-Fluent Assertions
-xUnit
-EntityFrameworkCore.InMemory
Database is held inside InMemory database. It doesn't need any setup to work. It's filled with dummy data.
Tests can be run from the top bar as normal. The .Tests file should automatically a connection to BookStoreAPI solution. If all goes well, the tests should execute successfully.