Welcome to the Simple Library CRUD API documentation application. This API allows restful operations on Books, Authors & Publisher Information.
Before you start, make sure you have the following prerequisites installed on your system:
- Dotnet Sdk (>= 8.0)
- RabbitMQ
- Redis
- Database (e.g., MSSQL) or Cloud MSSQL. In this project, Cloud SQL Server database was used
-
Clone this repository: Open a terminal and run
git clone https://github.com/7j4n1/BookApi.git cd BookApi
-
Install the dotnet packages for the project in the project by running:
dotnet build
-
Configure your application settings in the appsettings.json:
cp appsettings.Development.json appsettings.json
Configure the database, redis and rabbitmq config variables as follows:
"AllowedHosts": "*", "RedisCloudUrl": "redis-hostname:port,password=your-password", "RabbitMqUrl": "your-rabbitmqsetting-endpoint-goes-here", "ConnectionStrings": { "DefaultConnection" : "Data Source=mssql-servername;Initial Catalog=database-name;User ID=username;Password=password;TrustServerCertificate=true;" }
-
Ensure that you've started them 3 servers (Redis, SQL Server, RabbitMQ)
-
Run the migrations:
dotnet build dotnet-ef migrations add "Migration Name" dotnet-ef database update - to update the database with the Api Models
-
Start the development server:
dotnet run | dotnet run --launch-profile https (To force run on https scheme)
BookApi API is now up and running on {https://localhost:7057} which is the base url!
-
Open a browser and navigate to https://localhost:7057/swagger to see an API documentation
The API uses JSON for both requests and responses. The following table describes the JSON format for the requests and responses:
Requests | Response |
---|---|
POST /api/v1/Books | 201 Created with the newly created book in the response body |
GET /api/v1/Books | 200 OK with an array of Books in the response body. |
GET /api/v1/Books/{id} | 200 OK with the book with the specified id in the response body. |
PUT /api/v1/Books/{id} | 200 OK with the updated book in the response body. |
DELETE /api/v1/Books/{id} | 204 No Content |
Requests | Response |
---|---|
POST /api/v1/Authors | 201 Created with the newly created author in the response body |
GET /api/v1/Authors | 200 OK with an array of Authors in the response body. |
GET /api/v1/Authors/{id} | 200 OK with the author with the specified id in the response body. |
PUT /api/v1/Authors/{id} | 200 OK with the updated author in the response body. |
DELETE /api/v1/Authors/{id} | 204 No Content |
Requests | Response |
---|---|
POST /api/v1/Publishers | 201 Created with the newly created publisher in the response body |
GET /api/v1/Publishers | 200 OK with an array of Publishers in the response body. |
GET /api/v1/Publishers/{id} | 200 OK with the publisher with the specified id in the response body. |
PUT /api/v1/Publishers/{id} | 204 OK with no content |
DELETE /api/v1/Publishers/{id} | 204 No Content |
Requests | Response |
---|---|
GET /api/v1/Notification | 200 OK with a single notification fetched from the Queue Consumer in the response body. |
Once a new Book is uploaded from the /Books enpoint, The RabbitMQ Producer publish the new book info and a message "New book has been published" to the Queue and the Notification enpoint uses an async Class Method to get consume the message from the queue through the route "new_book".
And if no new Book published, the Nofitication return "No new book published"
The MIT License (MIT)