Code Monkey home page Code Monkey logo

books-crud's Introduction

Books API

Description

This project provides an API to retrieve, add, update, and delete books in a collection. The API has the following endpoints:

  • GET /books: Retrieves the list of books.
  • POST /add_book: Adds a new book to the collection.
  • GET /books/book/{id}: Retrieves a book by its ID.
  • GET /books/author/{author}: Retrieves a book by its author.
  • DELETE /books/{id}: Deletes a book by its ID.
  • PUT /books/{id}: Updates a parameter of a book.

Dependencies

This project has three dependencies that need to be installed using pip:

fastapi uvicorn pytest pylint psycopg2

To install the dependencies, you can also run the following command: pip install -r requirements.txt

The requirements.txt file lists the dependencies and their versions, and can be used to install them all at once.

Local deployment

To run the api on a local server, use the following command:

uvicorn api:app --reload

How to access the endpoint GET /books and retrieve the list of books

To retrieve the list of books, send a GET request to the /books endpoint. The API will return a JSON response with the list of books in the collection.

How to access the endpoint POST /add_book to add a new book

To add a new book to the collection, send a POST request to the /add_book endpoint with a JSON payload containing the parameters for the new book.

The parameters that can be included are:

  • title (required)
  • author (required)
  • releaseYear (required)
  • ISBN (required)
  • publisher (optional)
  • genre (optional)
  • format (optional)
  • description (optional)

How to access the endpoint GET /books/book/{id} to retrieve a book by its ID

To retrieve a book by its ID, send a GET request to the /books/book/{id} endpoint. The {id} parameter in the endpoint URL should be replaced with the ID of the book you want to retrieve.

How to access the endpoint GET /books/author/{author} to retrieve a book by its author

To retrieve a book by its author, send a GET request to the /books/author/{author} endpoint. The {author} parameter in the endpoint URL should be replaced with the name of the author you want to retrieve.

How to access the endpoint DELETE /books/{id} to delete a book by its ID

To delete a book by its ID, send a DELETE request to the /books/{id} endpoint. The {id} parameter in the endpoint URL should be replaced with the ID of the book you want to delete.

How to access the endpoint PUT /books/{id} to update a parameter of a book

To update a parameter of a book, send a PUT request to the /books/{id} endpoint with a JSON payload containing the updated parameters for the book.

The parameters that can be included are:

  • title
  • author
  • releaseYear
  • publisher
  • genre
  • format
  • description

The {id} parameter in the endpoint URL should be replaced with the ID of the book you want to update.

Running tests

The project includes a test suite to ensure the API is working correctly. To run the tests, run the test_api.py file. This will run the following tests:

test_add_book: Tests that the /add_book endpoint adds a new book to the collection. test_get_all_books: Tests that the /books endpoint returns a list of books. test_get_book_by_id: Tests that the /books/books/{id} endpoint retrieves a book by its ID. test_get_book_by_author: Tests that the /books/author/{author} endpoint retrieves books by author. test_update_book: Tests that the /books/{id} endpoint updates an existing book in the collection. test_delete_book_by_id: Tests that the /books/{id} endpoint deletes a book by its ID.

To run the tests, follow these steps:

  1. Make sure the API is not running.
  2. Open a terminal and navigate to the project directory.
  3. Run the following command:

pytest test_api.py

The pytest command will run all the tests in the test_api.py file. The output will indicate whether each test passed or failed, along with any error messages that were raised.

CI

books-crud's People

Contributors

alesr avatar wiltait avatar

Watchers

 avatar  avatar

books-crud's Issues

Implement endpoint for adding books

As a Backend Developer, I want to implement a POST endpoint in the "books-crud" repository that allows clients to add new books to the in-memory database using HTTP POST requests so that the database can be updated with new book entries.

Acceptance Criteria:

  • A POST endpoint is implemented in the "books-crud" repository that listens for incoming HTTP POST requests.
  • The POST endpoint accepts a request body containing the parameters for a new book (e.g. title, author, release year, etc.).
  • The POST endpoint adds the new book to the in-memory database and returns a response with a status code of 201 (Created) to indicate that the book has been successfully added.
  • The repository README is updated to include documentation on how to access the POST endpoint and submit new book entries.

Use Docker container to run the application

As a Backend Developer, I want to containerize the "books-crud" application using Docker so that it can be easily deployed and run on any platform that supports Docker.

Acceptance Criteria:

  • A Dockerfile is created for the "books-crud" application that specifies how to build a Docker image for the application.
  • The Dockerfile is configured to use an Alpine Linux distribution as the base image for the application.
  • The Docker image is built and tested locally to ensure that it runs correctly and serves the "books-crud" application.
  • The repository README is updated to include documentation on how to build and run the Docker image for the "books-crud" application, including commands for managing the Docker container.

Document the API for the books-crud application using Swagger

As a Backend Developer, I want to document the API for the "books-crud" application using Swagger so that clients can easily understand how to use the API and its various endpoints.

Acceptance Criteria:

  • The API for the "books-crud" application is documented using Swagger.
  • The Swagger documentation includes descriptions of the API's various endpoints and their parameters, as well as examples of the requests and responses that can be expected when using the API.
  • The Swagger documentation is accessible to clients through a publicly-available URL.
  • The repository README is updated to include a link to the Swagger documentation for the API.

Implement endpoint for deleting books

As a Backend Developer, I want to implement an endpoint in the "books-crud" repository that allows clients to delete existing books from the in-memory database using HTTP DELETE requests so that the database can be updated to remove outdated or unwanted book entries.

Acceptance Criteria:

  • A DELETE endpoint is implemented in the "books-crud" repository that listens for incoming HTTP DELETE requests.
  • The DELETE endpoint accepts a request containing the ID of the book to be deleted.
  • The DELETE endpoint removes the specified book from the in-memory database and returns a response with a status code of 200 (OK) to indicate that the delete operation was successful.
  • The repository README is updated to include documentation on how to access the DELETE endpoint and delete book entries.
  • Unit tests are implemented.

Implement a REST API returning "Hello, Will" on the endpoint GET /hello

As a Backend Developer, I want to implement a REST API that returns "Hello, Will" on the endpoint GET /hello in the "books-crud" repository so that I can demonstrate the ability to create and deploy a basic API endpoint.

Acceptance Criteria:

  • A REST API is implemented in the "books-crud" repository that listens for incoming HTTP requests on the endpoint GET /hello.
  • When a request is received on the GET /hello endpoint, the API returns a response with a status code of 200 and a body containing the string "Hello, Will".
  • The API is deployed and accessible to clients via a public URL (no authentication needed).
  • The repository README is updated to include documentation on how to access the API and make requests to the GET /hello endpoint.
  • Unit tests are implemented.

Replace in-memory DB by Postgres implementation

As a Backend Developer, I want to replace the in-memory database used by the "books-crud" application with a Postgres database so that the application can store data more persistently and scale better to handle larger workloads.

Acceptance Criteria:

  • The "books-crud" application is modified to use a Postgres database for storing data instead of an in-memory database.
  • The Postgres database is set up and configured according to the application's requirements (e.g. schema, tables, indices, etc.).
  • The unit tests for the "books-crud" application are modified to use a test Postgres database instead of the in-memory database, so that they can be run on GitHub Actions without the need for a local Postgres installation.
  • The repository README is updated to include documentation on how to set up and configure the Postgres database for the "books-crud" application.

Set up GitHub Action for linting and testing the code

As a Backend Developer, I want to set up a GitHub Action in the "books-crud" repository that runs the unit tests and linting checks whenever new code is pushed to the repository so that I can automatically verify the quality and style of the code and ensure that it meets certain standards before it is deployed to production.

Acceptance Criteria:

  • A GitHub Action is set up in the "books-crud" repository that runs the unit tests and linting checks whenever new code is pushed to the repository.
  • The GitHub Action is able to detect and report the results of the unit tests and linting checks, including any failures or errors.
    The repository README is updated to include documentation on how to trigger the GitHub Action and run the unit tests and linting checks.

Add book resource attributes

As a Backend Developer, I want to modify the GET /books endpoint in the "books-crud" repository to include additional book parameters in the response so that clients can access more detailed information about each book.

Acceptance Criteria:

  • The GET /books endpoint is modified to include additional book parameters in the response body, such as the title, author, release year, and ISBN of each book.
  • The response body is formatted in a way that makes it easy for clients to access the book parameters (e.g. as a JSON object).
  • The repository README is updated to include documentation on the new parameters that are included in the response body.
  • Unit tests are implemented.

NOTE:

The in-memory database is updated to include the additional book parameters.
Pseudo-code for updating the book object and the in-memory database:

// Update the book object to include additional parameters
let book = {
  id: 1,
  title: 'Vasco da Gama, O melhor do Brasil',
  author: '',
  releaseYear: 2010,
  ISBN: '978-0743273534',
  publisher: 'CBF',
  genre: "Document'',
  format: 'Paperback',
  description: 'Um pouco sobre a história sobre o maior e melhor time brasileiro de todos os tempos.'
}

// Update the in-memory database to include the additional parameters
books.push(book)

Implement endpoint for getting books by id

As a Backend Developer, I want to implement an endpoint in the "books-crud" repository that allows clients to retrieve a specific book by its ID using an HTTP GET request so that clients can access detailed information about individual books.

Acceptance Criteria:

  • A GET endpoint is implemented in the "books-crud" repository that listens for incoming HTTP GET requests on the endpoint GET /books/:id.
  • The GET endpoint accepts a request containing the ID of the book to be retrieved.
  • The GET endpoint retrieves the book with the specified ID from the in-memory database and returns it to the client in the response body.
  • The GET endpoint returns a response with a status code of 200 (OK) if the book is found, and a status code of 404 (Not Found) if the book is not found.
  • The repository README is updated to include documentation on how to access the GET /books/:id endpoint and retrieve a specific book.

Implement endpoint for getting books by author name

As a Backend Developer, I want to implement an endpoint in the "books-crud" repository that allows clients to retrieve a list of books by a specific author using an HTTP GET request so that clients can easily find all books written by a particular author.

Acceptance Criteria:

  • A GET endpoint is implemented in the "books-crud" repository that listens for incoming HTTP GET requests on the endpoint GET /authors/:name/books.
  • The GET endpoint accepts a request containing the name of the author for which to search.
  • The GET endpoint searches the in-memory database for books written by the specified author and returns a list of matching books in the response body.
  • The GET endpoint returns a response with a status code of 200 (OK) if at least one book is found, and a status code of 404 (Not Found) if no books are found.
  • The repository README is updated to include documentation on how to access the GET /authors/:name/books endpoint and search for books by author name.

Implement endpoint for modifying books

As a Backend Developer, I want to implement an endpoint in the "books-crud" repository that allows clients to modify existing books in the in-memory database using HTTP PUT requests so that the database can be updated with new book information.

Acceptance Criteria:

  • A PUT endpoint is implemented in the "books-crud" repository that listens for incoming HTTP PUT requests.
  • The PUT endpoint accepts a request body containing the updated parameters for a book (e.g. title, author, release year, etc.).
  • The PUT endpoint modifies the existing book in the in-memory database with the new parameters and returns a response with a status code of 200 (OK) to indicate that the update was successful.
  • The repository README is updated to include documentation on how to access the PUT endpoint and submit updates to existing book entries.
  • Unit tests are implemented.

Document Github Repository

As a Backend Developer, I want to create a Github repository called "books-crud" so that I have a place to store and version control my code for a project that involves creating, reading, updating, and deleting records for a collection of books.

Acceptance Criteria:

  • The repository is created on Github and has the name "books-crud" under the organization https://github.com/WillDev-Co.
  • The repository README contains a description of the project, including its purpose and any relevant information about the code that will be stored in the repository.
  • The repository README includes instructions for how to set up and run the code, as well as any dependencies that need to be installed.

Implement an endpoint for listing books

As a Backend Developer, I want to implement an endpoint for listing books in the "books-crud" repository that uses a simple in-memory database so that I can demonstrate the ability to retrieve data from a database and return it to clients via an API endpoint.

Acceptance Criteria:

  • An endpoint is implemented in the "books-crud" repository that listens for incoming HTTP requests on the endpoint GET /books.
  • When a request is received on the GET /books endpoint, the endpoint retrieves a list of books from an in-memory database and returns it to the client in the response body. Use JSON format for the response.
  • The in-memory database is created by initializing an array or object to store the data, and adding book objects to the array or object as needed.
  • The repository README is updated to include documentation on how to access the endpoint and retrieve the list of books.
  • Unit tests are implemented.

NOTE:

As we don't have any books yet on our system. Return a list of hard-coded values, as in, [book_name1, book_name2, book_name3].

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.