Coder Social home page Coder Social logo

exp-book's Introduction

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.

exp-book's People

Contributors

dependabot[bot] avatar dfirebird avatar

Watchers

 avatar

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.