https://github.com/mdrokz/books_crud_api_assignment
https://github.com/mdrokz/books_crud_api_assignment
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mdrokz/books_crud_api_assignment
- Owner: mdrokz
- Created: 2023-10-30T08:59:57.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-02-21T02:13:19.000Z (over 1 year ago)
- Last Synced: 2025-01-11T03:27:24.234Z (9 months ago)
- Language: TypeScript
- Size: 62.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Books CRUD API
A simple CRUD API for managing books, built using Fastify and MongoDB.
## Features
* CRUD Operations: Create, Read, Update, and Delete books.
* Fast: Built with Fastify for optimal performance.
* MongoDB Integration: Uses MongoDB as a data store.## API Endpoints
### Get All Books
* Endpoint: /books
* Method: GET
* Description: Fetches all books from the database.### Get a Single Book
* Endpoint: /books/:id
* Method: GET
* Description: Fetches a single book by its ID.### Add a New Book
* Endpoint: /books
* Method: POST
* Body:
```json
{
"title": "Book Title",
"author": "Author Name"
}
```
* Description: Adds a new book to the database.### Update a Book
* Endpoint: /books/:id
* Method: PUT
* Body:
```json
{
"title": "Updated Title",
"author": "Updated Author"
}
```
* Description: Updates an existing book by its ID.### Delete a Book
* Endpoint: /books/:id
* Method: DELETE
* Description: Deletes a book by its ID.## Prerequisites
* Docker
* Node
* NPM## Setup & Running
### Clone the Repository:
#### Start by cloning the repository to your local machine:
```bash
git clone https://github.com/mdrokz/books_crud_api_assignment
cd books_crud_api_assignment
Build and Run with Docker Compose:
```### Tests
You need a local mongodb instance for connection as i havent added test runner in docker image build time
```bash
npm test
```#### Use Docker Compose to build and run the application:
```bash
docker-compose up --build
The --build flag ensures that Docker builds the image using the provided Dockerfile. Once built, Docker Compose will start the services defined in docker-compose.yml.
```### Running without docker
You can use the build & start scripts present in package.json
You will also need to change the .env to your local mongodb connection
```bash
npm run build
``````
npm start
```### Deployment
I have setup fly.io for deployments
```bash
fly deploy
```#### Access the Application:
With the services running, you can access the Node.js application in your browser or through any API client at:
fly.io https link - https://books-crud-api.fly.dev/books
```
http://localhost:8080
Adjust the port (8080 in this example) if your docker-compose.yml specifies a different port mapping.
```