dfireBird / exp-book

API created for DSC recruitment task

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

exp-book

REST API for retrieving information author and books (retrieved from goodreads).

Scripts

Use the script provided in src/bin/csv_to_data.ts to import author csv from data into the database, with the following format:

$ yarn run import <csv_file>

or

$ npx ts-node src/bin/csv_to_data.ts <csv_file>

Endpoints

  • GET /authors - retrieve paginated list of information about authors
  • POST /books - create a book record
  • GET /books - retrieve book records
  • PUT /books/:id - update existing record of a book provided with id
  • DELETE /books/:id - delete a book record provided with id

GET /authors

Returns a paginated list of information about authors.

Query Parameters:

  • page - number of page you want to retrieve (default: 1)
  • limit - number of items in a single page (default: 10)

Response structure:

[
  {
    "id": <id>,
    "name": <author_name>,
  }
  ...
]

POST /books

Create a record containing the information of book.

Request Body

Send post request ot the endpoint with the following request body

{
  "name": "<name_of_the_book>",
  "edition": "<edition_number_of_book>",
  "publication_year": "<year_of_publication_of_book>",
  "authors": "<array_of_author_id_from_author_endpoint>"
}

GET /books

Retrieve a records about book information.

Query Parameters:

  • name - name the book (optional)
  • publication_year - year of publication of the book (optional)
  • edition - edition of the book (optional)
  • author - name of the author (optional)

Response Structure

[
  {
    "id": "<id>",
    "name": "<name_of_the_book>",
    "edition": "<edition_of_book>",
    "authors": "<array_of_author_of_book>"
  }
  ...
]

PUT /books/:id

Update existing records of a book. Identified using id.

Request Body

{
  "name": "<name_of_the_book_if_wanted_to_change>",
  "edition": "<edition_of_the_book_if_wanted_to_change>",
  "publication_year": "<publication_year_of_the_book_if_wanted_to_change>",
  "authors": "<array_of_author_ids_if_wanted_to_change>"
}

DELETE /book/:id

Delete a record of a book. Identified using id.

Deployment

Create a .env file with the following information:

POSTGRES_USER=<postrgres_username>
POSTGRES_PASSWORD=<postrgres_password>
POSTGRES_DB=<postgres_db_name>

Docker-Based

Prerequisite

  • Docker
  • docker-compose

Run the docker-compose to start the API server.

$ docker-compose up

Local Deployment (Without Docker)

Prerequisite

  • postgres
  • node version > 12
  • yarn

Install the node dependencies

$ yarn

Ensure that you have postrgres installed and it’s running on your system then start the server.

$ yarn start

Usage

Navigate to localhost:8080 and access the endpoints

License

This project uses a MIT License, which can be viewed here here.

About

API created for DSC recruitment task

License:MIT License


Languages

Language:TypeScript 98.8%Language:Dockerfile 1.2%