Skip to content

APIs for Book review system using NestJs, GraphQL Apollo server, Prisma ORM, PostgresSQL , JWT

Notifications You must be signed in to change notification settings

rohit114/book-review-sys

Repository files navigation

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Support us

Introduction

  • The Book Review System API allows users to add books, create, edit, and delete review. Users can sign up for an account, log in to obtain an access token, and use this token to authenticate their requests. Unauthorized access attempts will result in a 403 Forbidden response.

  • To access protected endpoints, users must include their access token in the request headers under the Authorization field. Without a valid access token, users will not be able to perform actions on the system.

  • This system has GraphQL based queries where a user can get his written reviews, others reviews, add books, search books by author and title

  • The API returns standard HTTP status codes to indicate the success or failure of requests. Error responses include detailed messages to assist developers in troubleshooting issues.APIs will throw bad request upon faling any input validations

Tech stack used:

  • NodeJs V16.0.0+
  • TypeScript V5.4.5+
  • NestJs V10.3.2+
  • PostgreSQL V14.1.0+
  • Prisma V5.16.1
  • Apollo 12.2.0

Setting up project:

1 clone the repo: https://github.com/rohit114/book-review-sys.git
2 cd book-review-sys
3 npm install
4 add these variable in .env file JWT_SECRET_KEY = "xxxxxxDATABASE_URL = "postgresql://postgres@localhost:5432/book_review"
5 prisma migrate dev --name init
6 npm start

API Documentation:

  1. Register User:

    • METHOD: POST
    • URL: {{BASE_URL}}/apis/book-review-sys/v1/user/register
    • BODY: {"name":"Rohit","username":"rohit114","email":"rohitkumardas114@gmail.com","password":"ur_password"}
    • api will return created user with user_id with status code 201
  2. User Login to get the access-token:

    • METHOD: POST
    • URL: {{BASE_URL}}/apis/book-review-sys/v1/user/login
    • BODY: {"email":"rohit@example.com", "password": "ur_password"}
    • Api will return the access_token, use this token in request header Authorization for api calls
  3. Add Book:

    • METHOD: POST
    • HEADER: Authorization
    • URL: {{BASE_URL}}/apis/book-review-sys/v1/book/add
    • BODY: {"title":"Atomic Habits","author_id":1,"published_year":"2018-10-16"}
    • Api will return newly added book
  4. Add Review:

    • METHOD: POST
    • HEADER: Authorization
    • URL: {{BASE_URL}}/apis/book-review-sys/v1/review/add
    • BODY: {"book_id":1,"rating":10,"comment":"awesome book"}
    • Api will return newly added review
  5. Update Review:

    • METHOD: POST
    • HEADER: Authorization
    • URL: {{BASE_URL}}/apis/book-review-sys/v1/review/update
    • BODY: {"review_id":1,"rating":9,"comment":"must read, amazing book"}
    • Api will return updated review or Forbidden for unauthorized user
  6. Delete Review:

    • METHOD: DELETE
    • HEADER: Authorization
    • URL: {{BASE_URL}}/apis/book-review-sys/v1/review/delete/1
    • Api will return true on success or Forbidden for unauthorized user
  7. GraphQL Search Queries:

    • METHOD: POST

    • HEADER: Authorization

    • URL: {{BASE_URL}}/graphql

    • BODY: ur query

      Get all books with pagination:

      { "query": "{ getBooks(offset: 3, limit: 8) { id title author { id username } publishedYear } }"}
      

      Get book by id

        "query": "{ getBookById(id: 1) { id title author { id username } publishedYear } }"
      

      Search book

        { "query": "{searchBooks(searchTerm: \"nodejs\") {id title author { id username } publishedYear}}" }
      

      Get all reviews with pagination:

        "query": "{ getReviews(offset: 0, limit: 10) { id rating, comment book {id, title, publishedYear } user {id, username}  } }"
      

      Get my reviews:

        "query": "{ getMyReviews(userId: 24, offset: 0, limit: 10) { id rating, comment book {id, title, publishedYear } user {id, username}  } }"
      
  • You can find the all curl of the apis in the postman collection book-review-sys.postman_collection.json inside the book-review-sys repo

Stay in touch

About

APIs for Book review system using NestJs, GraphQL Apollo server, Prisma ORM, PostgresSQL , JWT

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published