/casestudy-api-book

Case study for developing a robust REST API for managing a collection of books, supporting CRUD operations and API endpoints.

Primary LanguageJavaScriptMIT LicenseMIT


Case Study: RESTful Books API

An awesome README template to jumpstart your projects!
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Optimizations
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

About The Project

Product Name Screen Shot

There are many great README templates available on GitHub; however, I didn't find one that really suited my needs so I created this enhanced one. I want to create a README template so amazing that it'll be the last one you ever need -- I think this is it.

Here's why:

  • Your time should be focused on creating something amazing. A project that solves a problem and helps others
  • You shouldn't be doing the same tasks over and over like creating a README from scratch
  • You should implement DRY principles to the rest of your life 😄

Of course, no one template will serve all projects since your needs may be different. So I'll be adding more in the near future. You may also suggest changes by forking this repo and creating a pull request or opening an issue. Thanks to all the people have contributed to expanding this template!

Use the BLANK_README.md to get started.

(back to top)

Built With

This section should list any major frameworks/libraries used to bootstrap your project. Leave any add-ons/plugins for the acknowledgements section. Here are a few examples.

  • Next
  • React
  • Vue
  • Angular
  • Svelte
  • Laravel
  • Bootstrap
  • JQuery

(back to top)

Getting Started

This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.

Prerequisites

This is an example of how to list things you need to use the software and how to install them.

  • npm
    npm install npm@latest -g

Installation

Below is an example of how you can instruct your audience on installing and setting up your app. This template doesn't rely on any external dependencies or services.

  1. Get a free API Key at https://example.com
  2. Clone the repo
    git clone https://github.com/your_username_/Project-Name.git
  3. Install NPM packages
    npm install
  4. Enter your API in config.js
    const API_KEY = 'ENTER YOUR API';

(back to top)

Usage

Use this space to show useful examples of how a project can be used. Additional screenshots, code examples and demos work well in this space. You may also link to more resources.

For more examples, please refer to the Documentation

(back to top)

Optimizations

  • Refactor Code
    • Refactor using mongoose instead of mongodb
  • Error Handling
    • Identify additional edge cases
  • Improve FrontEnd
    • EJS (Embedded JavaScript Templating) is used for demo purposes.
    • Consider similar dynamic frameworks and libraries such as React.js for DOM manipulation.
  • Sorting Functionality

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Your Name - @your_twitter - email@example.com

Project Link: https://github.com/your_username/repo_name

(back to top)

Acknowledgments

Use this space to list resources you find helpful and would like to give credit to. I've included a few of my favorites to kick things off!

(back to top)

Prompt

You are tasked with developing a robust REST API using Node.js for managing a collection of books. The API should support CRUD operations (Create, Read, Update, Delete) for books. Below are the required endpoints and their functionalities:

  1. GET /books: Retrieve a list of all books. Implement pagination to limit the number of books returned per request.
  2. GET /books/{id}: Retrieve details of a specific book by ID.
  3. POST /books: Add a new book to the collection. Implement input validation to ensure all required fields are provided (title, author, publicationYear), and publicationYear should be a valid year in the past.
  4. PUT /books/{id}: Update details of a specific book by ID. Allow partial updates, and ensure validation is applied to the input data.
  5. DELETE /books/{id}: Delete a specific book by ID.
  6. GET /books/search?q={query}: Implement search functionality to allow users to search for books by title or author.
  7. GET /books/stats: Provide statistics about the collection of books, including the total number of books, the earliest and latest publication years, and any other relevant metrics you think are appropriate.

Each book should have the following attributes:

  • id (unique identifier)
  • title
  • author
  • publicationYear

Data

You can structure the data in a MySQL or MongoDB database. Here's an example of how the data might look:

const books = [
  { id: 1, title: 'The Great Gatsby', author: 'F. Scott Fitzgerald', publicationYear: 1925 },
  { id: 2, title: 'To Kill a Mockingbird', author: 'Harper Lee', publicationYear: 1960 },
  { id: 3, title: '1984', author: 'George Orwell', publicationYear: 1949 }
];

Output Requirements

  • The API should be RESTful and follow best practices.
  • Implement pagination for listing books.
  • Implement proper input validation for POST and PUT endpoints.
  • Implement search functionality using query parameters.
  • Include comprehensive error handling and appropriate status codes.
  • Write clean, well-structured, and maintainable code.
  • Include thorough documentation and comments.

Evaluation Criteria

  • Correctness and completeness of API implementation.
  • Implementation of pagination, search, and statistics functionality.
  • Quality of code (readability, maintainability, efficiency).
  • Adherence to RESTful principles and best practices.
  • Error handling, input validation, and edge cases handling.
  • Documentation quality and completeness.

Submission

  • The candidate should deliver the completed project via email the next day.
  • The submission should be a compressed folder containing the project files.
  • Include a README file with instructions on how to run the application locally.
  • Ensure the project is well-organized and easy to understand. Database dump file

Additional Notes

  • Utilize asynchronous programming paradigms where appropriate.
  • Implement unit tests to ensure the reliability of the API.
  • Consider scalability and performance optimizations.
  • You can include any additional features or improvements you think are appropriate to showcase your skills.