A comprehensive RESTful API for managing a book store with books, authors, categories, and user authentication.
- RESTful APIs - Complete CRUD operations for all entities
- Entity Framework Core - Database-first approach with PostgreSQL
- Repository Pattern - Clean separation of data access logic
- AutoMapper - Object-to-object mapping between models and DTOs
- FluentValidation - Comprehensive input validation
- JWT Authentication - Secure user authentication and authorization
- Swagger Documentation - Interactive API documentation
- CORS Support - Cross-origin resource sharing enabled
- Users - User accounts with authentication
- Categories - Book categories/genres
- Authors - Book authors with biographical information
- Books - Book information with relationships to categories and authors
- Books → Categories (Many-to-One)
- Books → Authors (Many-to-One)
- Books → Users (Many-to-One) - Track who added the book
- .NET 9.0 SDK
- PostgreSQL Database
- Your database credentials:
- Host: localhost
- Port: 5555
- Database: bookstore
- Username: postgres
- Password: 9900
-
Clone the repository
git clone <repository-url> cd bookapi
-
Install dependencies
dotnet restore
-
Update database connection (if needed)
- Edit
appsettings.jsonto match your PostgreSQL configuration
- Edit
-
Run the application
dotnet run
-
Access the API
- Swagger UI: http://localhost:5000
- API Base URL: http://localhost:5000/api
POST /api/auth/register- Register a new userPOST /api/auth/login- Login user
GET /api/books- Get all booksGET /api/books/{id}- Get book by IDPOST /api/books- Create new book (requires authentication)PUT /api/books/{id}- Update book (requires authentication)DELETE /api/books/{id}- Delete book (requires authentication)GET /api/books/search?q={term}- Search booksGET /api/books/category/{categoryId}- Get books by categoryGET /api/books/author/{authorId}- Get books by authorGET /api/books/price-range?minPrice={min}&maxPrice={max}- Get books by price range
GET /api/categories- Get all categoriesGET /api/categories/{id}- Get category by IDPOST /api/categories- Create new categoryPUT /api/categories/{id}- Update categoryDELETE /api/categories/{id}- Delete category
GET /api/authors- Get all authorsGET /api/authors/{id}- Get author by IDPOST /api/authors- Create new authorPUT /api/authors/{id}- Update authorDELETE /api/authors/{id}- Delete author
The API uses JWT (JSON Web Tokens) for authentication. To access protected endpoints:
- Register or login to get a token
- Include the token in the Authorization header:
Authorization: Bearer <your-token>
- Username: 3-50 characters, alphanumeric and underscores only
- Email: Valid email format, max 100 characters
- Password: Min 6 characters, must contain uppercase, lowercase, and number
- First/Last Name: Optional, letters and spaces only
- Title: Required, 2-200 characters
- Price: Required, greater than 0, less than 10,000
- ISBN: Optional, alphanumeric with hyphens and X
- Publication Year: Optional, between 1800 and current year
- Pages: Optional, greater than 0, less than 10,000
- Category and Author IDs: Required, must exist in database
- Name: Required, 2-100 characters, unique
- Description: Optional, max 500 characters
- Full Name: Required, 2-100 characters, letters and spaces only
- Bio: Optional, max 1000 characters
- Date of Birth: Optional, cannot be in the future
- Nationality: Optional, max 50 characters, letters and spaces only
bookapi/
├── Controllers/ # API Controllers
├── Data/ # Entity Framework DbContext
├── DTOs/ # Data Transfer Objects
├── Models/ # Entity Models
├── Repositories/ # Repository Pattern Implementation
├── Services/ # Business Logic Services
├── Validators/ # FluentValidation Rules
├── wwwroot/ # Static Files
├── Program.cs # Application Entry Point
├── appsettings.json # Configuration
└── README.md # This file
- .NET 9.0 - Latest .NET framework
- Entity Framework Core - ORM for database operations
- PostgreSQL - Relational database
- AutoMapper - Object mapping
- FluentValidation - Input validation
- JWT Bearer - Authentication
- Swagger/OpenAPI - API documentation
- Repository Pattern - Data access abstraction
This project demonstrates:
- RESTful API design principles
- Entity Framework Core with Fluent API
- Repository pattern implementation
- DTOs and AutoMapper usage
- Comprehensive validation with FluentValidation
- JWT authentication implementation
- Swagger documentation setup
- Clean architecture principles
Feel free to contribute to this project by:
- Adding new features
- Improving validation rules
- Enhancing error handling
- Adding unit tests
- Improving documentation
This project is for educational purposes.