The Books API provides a comprehensive set of endpoints to interact with a collection of books. It allows users to perform various operations related to books, including creating new books, retrieving book details, updating book information, and deleting books.
- Getting Started
- Usage
- Endpoint Version-1
- Drawbacks of Not Using Authentication
- Decisions and Assumptions
- Books API Version-2
- Deployment Process
These instructions will help you set up and run the project locally.
-
Clone the GitHub repository to your local machine:
git clone https://github.com/hafeez25/books_api.git cd books_api npm install -
Create a new
.envfile in your project directoy and setup according to the.env.examplefile:PORT=5000 JWT_SECRET=your_jwt_secret MONGO_URI=your_mongodb_uri CLOUD_NAME=your_cloudinary_cloud_name API_KEY=your_cloudinary_api_key API_SECRET=your_cloudinary_api_secret
-
Start the application by running the following command in your project directory:
node server.js
- Method:
POST - Endpoint:
https://tiny-red-beetle-boot.cyclic.app/api/v1/books - Description: Create a new book by providing the title, author, and a summary.
POST /api/v1/books
Content-Type: application/json
{
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"summary": "A tale of the American Dream in the 1920s."
}- Method:
GET - Endpoint:
https://tiny-red-beetle-boot.cyclic.app/api/v1/books - Description: Retrieve a list of all books in the books. Books are sorted in descending order by their unique identifiers.
- Method:
GET - Endpoint:
https://tiny-red-beetle-boot.cyclic.app/api/v1/books/:id - Description: Retrieve the details of a specific book by providing its unique identifier.
- Method:
PATCH - Endpoint:
https://tiny-red-beetle-boot.cyclic.app/api/v1/books/:id - Description: Update the information of a book using its unique identifier. This endpoint allows you to update specific fields of a book.
- Method:
DELETE - Endpoint:
https://tiny-red-beetle-boot.cyclic.app/api/v1/books/:id - Description: Delete a book from the books using its unique identifier.
Successful responses return the requested data or a success message with appropriate HTTP status codes (e.g., 200 OK, 201 Created).
In case of errors, the API responds with error messages and the appropriate HTTP status codes (e.g., 400 Bad Request for client errors, 404 Not Found for resource not found, and 500 Internal Server Error for server errors).
Not using authentication in the Books API can lead to several security and operational drawbacks, including:
-
Unauthorized Access: Without proper authentication, your API may be vulnerable to unauthorized access. This means anyone can send requests to your API, potentially causing data breaches or unauthorized usage.
-
Data Integrity: Lack of authentication can result in compromised data integrity. Users may tamper with or manipulate data, leading to incorrect or malicious information in your book collection.
-
Limited Access Control: Authentication is crucial for controlling who can perform sensitive operations. Without it, you have limited control over who can create, update, or delete books, potentially leading to misuse or accidental deletions.
-
Security Vulnerabilities: Without authentication, your API may be exposed to various security vulnerabilities, such as cross-site request forgery (CSRF) and unauthorized API access.
-
Audit Trails: Proper authentication allows you to maintain audit trails of API actions. Without it, tracking and auditing actions become challenging, hindering the ability to investigate any issues or incidents.
-
Compliance Requirements: Many industries and regulations require authentication and user access control to comply with data protection and privacy regulations. Neglecting authentication may result in non-compliance with legal requirements.
During the development process of my API, I made several key decisions and assumptions to enhance its functionality and user experience. These decisions include:
1. Implementation of the Book Search Feature:
- Decision: I decided to implement a robust book search feature to improve user accessibility and enable efficient content retrieval.
- Assumption: I assumed that users would benefit from a search functionality to find books based on various criteria, enhancing their overall experience.
2. Implementation of User Authentication:
- Decision: I incorporated user authentication to safeguard user data and provide controlled access to sensitive API endpoints.
- Assumption: I assumed that authentication is essential to ensure data privacy and security, allowing only authorized users to interact with the API.
3. Implementation of Book Cover Image Handling:
- Decision: I included book cover image handling to enhance the visual experience of my users by providing visual representations of books.
- Assumption: I assumed that visual content, such as book cover images, can greatly improve user engagement and book selection.
These decisions have been integral in shaping the capabilities and user-friendliness of my API. While they were based on assumptions and requirements, I will continue to validate and refine these features through testing and user feedback to ensure they meet user expectations.
Welcome to the Books API Version 2 documentation. This API offers an enhanced experience for managing books and user interactions.
- User Authentication: Securely register and log in to access the API's features.
- Book Search: Easily search for books within the database to find the information you need.
- Book Cover Images: Attach book cover images to enhance the visual representation of books.
Note: All new features are implemented in the dev branch
Create a new user account by providing the necessary information.
- Endpoint:
/api/v2/auth/register - Method:
POST - Request Body:
email(string) - The user's email address.name(string) - The user's name.password(string) - The user's password.
Authenticate an existing user by providing their email and password.
- Endpoint:
/api/v2/auth/login - Method:
POST - Request Body:
email(string) - The user's email address.password(string) - The user's password.
Search for books in the database
- Endpoint:
/api/v2/books/search?query={} - Method:
GET - Parameters:
query(string) - The search query.
To deploy your Node.js application with automatic updates from your GitHub repository to Cyclic.sh, follow these steps:
Step 1: Set Up a Cyclic.sh Account
Sign up for a Cyclic.sh account if you haven't already. Cyclic.sh is a powerful CI/CD platform designed for seamless deployment.
Step 2: Connect Your GitHub Repository
Within your Cyclic.sh account, establish a connection to your GitHub repository. This enables Cyclic.sh to access your repository and deploy changes automatically.
Step 3: Push Code Changes to GitHub
Make the necessary changes to your Node.js application, commit them, and then push these changes to your GitHub repository. Cyclic.sh will continuously monitor your repository for any updates.
Step 4: Automatic Deployment
Once changes are pushed to your GitHub repository, Cyclic.sh detects these modifications and automatically initiates the build and deployment process. This automated process updates your application on the Cyclic.sh server.
Step 5: Access Your Deployed Application
Following the completion of the deployment process, your Node.js application is up to date and accessible on the Cyclic.sh server. You can access it via the provided URL.
This streamlined deployment workflow ensures that your application is always kept current without manual intervention.