An open API service indexing awesome lists of open source software.

https://github.com/rashedul-alam46/library-api-sqlserver

REST API built with .NET, C#, and MS SQL Server
https://github.com/rashedul-alam46/library-api-sqlserver

csharp dotnet-core restful-api sql-server

Last synced: about 3 hours ago
JSON representation

REST API built with .NET, C#, and MS SQL Server

Awesome Lists containing this project

README

          

# Library API (SQL Server + Docker)

A .NET Core / .NET 9 Web API for managing a library system, backed by MS SQL Server.
This project is structured with clean architecture (Domain, Application, Infrastructure, API) and supports basic CRUD operations on books, authors, categories, publishers, etc.

---

## πŸ“ Repository Structure
```
LibraryApiSqlServer/
β”œβ”€β”€ Library.Api/ # API / presentation layer (controllers, endpoints)
β”œβ”€β”€ Library.Application/ # Application logic
β”‚ β”œβ”€β”€ Services/ # Business services / use cases
β”‚ └── DTOs/ # Data Transfer Objects, ViewModels
β”œβ”€β”€ Library.Domain/ # Domain / core (entities, interfaces)
β”œβ”€β”€ Library.Infrastructure/ # Data access, repository implementations, EF Core, DB context
β”œβ”€β”€ LibraryApiSqlServer.sln
β”œβ”€β”€ Program.cs
β”œβ”€β”€ appsettings.json
β”œβ”€β”€ appsettings.Development.json
└── README.md
```

---

## βš™οΈ Prerequisites

- [.NET 9 SDK](https://dotnet.microsoft.com/download) or compatible .NET version
- SQL Server instance (local or remote)
- [Docker Desktop](https://www.docker.com/products/docker-desktop/) for containerized setup (Optional)
- A tool like **SQL Server Management Studio (SSMS)** for DB inspection (Optional)

---

## πŸ”§ Setup / Getting Started

**1. Clone the repository**

```bash
git clone https://github.com/rashedulalam46/library-api-sqlserver.git
cd library-api-sqlserver
```

**2. Configure connection string**

Open appsettings.json or appsettings.Development.json, and set up your ConnectionStrings:DefaultConnection to point to your SQL Server.

```
{
"ConnectionStrings": {
"ConString": "Server=YOUR_SERVER;Database=LibraryDb;User Id=…;Password=…;"
}
}
```

If you are using Docker, then use

```
{
"ConnectionStrings": {
"ConString": "Server=host.docker.internal;Database=LibraryDb;User Id=…;Password=…;"
}
}
```

**3. Apply migrations / create database**

Run the SQL script located in **Library.Infrastructure/Data/DatabaseScript.sql** to create the database and tables.
Alternatively, to create the database and tables using Entity Framework, run the following command in the Infrastructure project (or from the solution root):

```
dotnet ef database update
```

This will create the database and necessary tables.

**4. Build & run the API**

```
dotnet build
dotnet run
```

The default launch URL might be https://localhost:5001 (or as configured). Use a tool like Postman, curl, or HTTPie to test the endpoints.

## πŸ›£οΈ API Endpoints (Examples)

These are sample endpoints β€” adjust according to actual implementation.
| Method | URL | Description |
| ------ | --------------- | ----------------------- |
| GET | /api/books | Get all books |
| GET | /api/books/{id} | Get book by ID |
| POST | /api/books | Create a new book |
| PUT | /api/books/{id} | Update an existing book |
| DELETE | /api/books/{id} | Delete a book by ID |

## βœ… Features & Highlights

- Clean / layered architecture (Domain, Application, Infrastructure)
- Dependency Injection
- EF Core as data access layer
- DTOs / ViewModels for input/output
- Configuration-based connection strings
- Exception handling, validation, etc. (if implemented)

## πŸ“¦ Deployment

When you’re ready to deploy:

- Configure the production connection string in environment variables.
- Publish the project:

```
dotnet publish --configuration Release
```

- Deploy the resulting output to your server / host / container.
- Ensure the database is accessible and migrations are applied.

## πŸ“„ License & Contribution

- Feel free to fork or suggest changes via pull requests.
- Add a LICENSE file if you have specific usage terms.
- Please document style, code conventions, etc., in a CONTRIBUTING.md.