@Ifycode's buuk API (nodejs, expressjs, mongodb)

Overview

@Ifycode/buuks-express-api


Hosted on Heroku: https://buuks-express-api.herokuapp.com

"Buuks" instead of "books"... Another angle 😉 The API allows an (authenticated) user to interact with a database made for storing books. API is built with nodejs, expressjs and mongoDB, and is able to do the following:

  • Create Read Update Delete operations for books which are saved in the database
  • User signup, authentication and (basic) authorization
  • PDF file upload to Cloudinary
  • Uses zod for resource validation

API design

Methods & endpoints Description Request body Auth (access token)
POST /users/signup Create new user email, password, passwordConfirmation, name Not required
POST /users/login Sign in as existing user, create access token and refresh token for use in all endpoints that require access token email, password Access token is generated at this endpoint
GET /users/sessions Gets all users sessions made through the POST /users/login endpoint. Also reissues an access token (if access token is expired and there's refresh token) No request body Use access token from the POST /users/login response
DELETE /users/sessions Deletes the last recorded session created through the POST /users/login endpoint (Note: this endpoint may need fixing) No request body Use access token from the POST /users/login response
POST /books Create a new book (authenticated user) title, description, pdf (file upload) Use access token from the POST /users/login response
GET /books/user/:userId Get/view only books created by a particular user, using the user ID No request body Use access token from the POST /users/login response
GET /books/:bookId Get/view a book stored in the database, using the book ID No request body Not required (for now)
PUT /books/:bookId Update already existing book in the database, using the book ID title, description, pdf (file upload) Use access token from the POST /users/login response
DELETE /books/:bookId Delete a book from the database, using the book ID No request body Use access token from the POST /users/login response

Request body and (successful) response

POST /users/signup
Request body

{
    "email": "string",
    "password": "string",
    "passwordConfirmation": "string",
    "name": "string"
}

Successful response (sample)

{
    "user": {
        "email": "string",
        "name": "string",
        "_id": "string",
        "createdAt": "string",
        "updatedAt": "string"
    }
}

POST /users/login
Request body

{
    "email": "string",
    "password": "string"
}

Successful response (sample)

{
    "user": {
        "name": "string",
        "email": "string",
        "_id": "string"
    },
    "accessToken": "string"
}

GET /users/sessions
Request body

No response body

Successful response (sample)

{
    "count": number,
    "sessions": [
        {
            "_id": "string",
            "user": "string",
            "password": boolean,
            "userAgent": "string",
            "createdAt": "string",
            "updatedAt": "string"
        },
        // etc.
    ]
}

DELETE /users/sessions
Request body

No response body

Successful response (sample)

{
    "accessToken": null,
    "refreshToken": null
}

POST /books
Request body

Use form-data (in postman). The title and description keys should have value of type string. The pdf key should have the value of type file.

Successful response (sample)

{
    "message": "string"
    "user": {
        "name": "string",
        "_id": "string"
    },
    "book": {
        "_id": "string",
        "title": "string",
        "description": "string",
        "pdf": "string"
        "request": {
            "type": "string",
            "url": "string",
            "description": "string"
        }
    }
}

GET /books/user/:userId
Request body

No response body

Successful response (sample)

{
    "count": number,
    "description": "string",
    "books": [
        {
            "_id": "string",
            "title": "string",
            "description": "string",
            "pdf": "string",
            "request": {
                "type": "string",
                "url": "string",
                "description": "string"
            }
        },
        // etc.
    ]
}

GET /books/:bookId
Request body

No response body

Successful response (sample)

{
    "_id": "string",
    "title": "string",
    "description": "string",
    "pdf": "string",
    "user": {
        "_id": "string"
    },
    "request": {
        "type": "string",
        "url": "string",
        "description": "string"
    }
}

PUT /books/:bookId
Request body

Use form-data (in postman). The title and description keys should have value of type string. The pdf key should have the value of type file.

Successful response (sample)

{
    "message": "string"
    "user": {
        "name": "string",
        "_id": "string"
    },
    "book": {
        "_id": "string",
        "title": "string",
        "description": "string",
        "pdf": "string"
        "request": {
            "type": "string",
            "url": "string",
            "description": "string"
        }
    }
}

DELETE /books/:bookId
Request body

No response body

Successful response (sample)

{
    "message": "string"
    "user": {
        "name": "string",
        "_id": "string"
    },
    "request": {
        "type": "string",
        "url": "string",
        "description": "string"
    }
}

Running the API in development

Make sure to either have mongoDB installed and running on your computer, or have a monogDB atlas cluster set up in the cloud. Set your API_HOST_URL and other needed environment variables in the .env file you create (see example in .env.example file). Use the commands below to run the API locally on your computer.

Install dependencies:

npm install

Start server for connection to mongoDB (local):

npm run dev

Start server for connection to mongoDB (Atlas):

npm run dev:atlas

Helpful learning (and bug fixing) resources

You might also like...

A peroidic-table api built with Nodejs & Mongodb to help make frontend requests dealing with chemistry...

A peroidic-table api for frontend apps Usage Example (GET all elements) // GET /api/elements const ajio = require("ajio") ajio.baseUrl("https://apis-

May 24, 2022

⚙️ REST api with NodeJS(KoaJS) MongoDB and Jest Tests.

RESTRIS Functional Backend implementation of REST api with NodeJS(KoaJS) MongoDB and Jest Tests. Tools TypeScript Node KoaJS MongoDB Mongoose Jest Sup

Dec 2, 2022

Nodejs,Expreess,Mongodb,Reactjs,Redux,Java app,Google,Docker,Heroku,...

Nodejs,Expreess,Mongodb,Reactjs,Redux,Java app,Google,Docker,Heroku,...

Tiến độ công việc Team: https://docs.google.com/spreadsheets/d/1BBv4CXNniNjqdIE7tjrG9UM4nprd3NSVy2FX9oaWq0Q/edit#gid=0 Web Online: https://movienetfli

Sep 17, 2022

Authentication system made with NodeJS and MongoDB.

Auth-API A authentication system made with NodeJS. It's a service where you can register your user, then use the credentials to login . What I used in

May 18, 2022

DocuBox is a cloud file storing app built using Kotlin, Nodejs and MongoDb.

DocuBox is a cloud file storing app built using Kotlin, Nodejs and MongoDb.

DocuBox is an app where you can securely upload your files on the cloud – from family pictures and audio recordings to spreadsheets, presentations and other confidential documents. All the files uploaded by the users are stored in an encrypted format.

Nov 18, 2022

CLI Progress Bar implemented in NodeJS to track Time, ETA and Steps for any long running jobs in any loops in JS, NodeJS code

CLI Progress Bar implemented in NodeJS to track Time, ETA and Steps for any long running jobs in any loops in JS, NodeJS code

NodeJS-ProgressBar CLI Progress Bar for NodeJS and JavaScript to track Time, ETA and Steps for any long running jobs in any loops in JS, NodeJS code D

Nov 14, 2022

A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and configure Typescript on it.

A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and configure Typescript on it.

CTSP- Create TS Project A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and conf

Sep 13, 2022

API of my readings, developed in Nest.js, MongoDB, Nginx and Dockerized

API of my readings, developed in Nest.js, MongoDB, Nginx and Dockerized

My Readings step by step for configuration with docker OBS: required docker and docker-compose cp -r .env.sample .env docker-compose up example what t

Jul 1, 2022

TypeSafe MongoDB Atlas Data API SDK for Deno & Deno Deploy

Atlas SDK atlas_sdk is a TypeSafe MongoDB Atlas Data API SDK for Deno & Deno Deploy Links Docs Import Replace LATEST_VERSION with current latest versi

Dec 26, 2022
Comments
  • Heroku deployment issues

    Heroku deployment issues

    Deployment url: https://buuks-express-api.herokuapp.com

    Tested on postman.

    Note: Looks like this issue occurs on Heroku when the size of the file you want to upload is large.

    The issue

    This happens when user is logged out: Post request to POST /books returns an html page structure instead of a response object. Also PUT /books/:bookID does this too sometimes. These are the only two endpoints I noticed does this. And they are the only two endpoints that have Cloudinary code in them... (I'm thinking it's related to cloudinary)

    <!DOCTYPE html>
    <html>
    
    <head>
    	<meta name="viewport" content="width=device-width, initial-scale=1">
    	<meta charset="utf-8">
    	<title>Application Error</title>
    	<style media="screen">
    		html,
    		body,
    		iframe {
    			margin: 0;
    			padding: 0;
    		}
    
    		html,
    		body {
    			height: 100%;
    			overflow: hidden;
    		}
    
    		iframe {
    			width: 100%;
    			height: 100%;
    			border: 0;
    		}
    	</style>
    </head>
    
    <body>
    	<iframe src="//www.herokucdn.com/error-pages/application-error.html"></iframe>
    </body>
    
    </html>
    

    The error message on heroku log says:

    2022-03-14T17:38:57.804725+00:00 app[web.1]: POST /books 403 0.650 ms - 96
    2022-03-14T17:38:58.044194+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=POST path="/books" host=buuks-express-api.herokuapp.com request_id=94e5ec60-bbda-4f0c-819b-008d486fb7f6 fwd="105.112.16.84" dyno=web.1 connect=0ms service=239ms status=503 bytes=310 protocol=https
    

    Expected json response

    {
        "message": "You are Logged out. Please sign in to your account to continue",
        "error": "Forbidden"
    }
    

    In development i.e. with localhost, the response returns JSON response object as expected

    opened by Ifycode 0
  • Book controller: Update book request should also replace PDF on Cloudinary

    Book controller: Update book request should also replace PDF on Cloudinary

    PUT /books/:booksId Only the url in the DB is updated. Update book does not replace PDF yet (at the moment, It just adds another PDF to the list which is not the desired outcome).

    opened by Ifycode 0
  • Use swagger for documenting API

    Use swagger for documenting API

    It's getting harder to track sync changes to the API to the "Request body and response breakdown" section of the readme. Document the API using e.g. swagger.

    opened by Ifycode 0
Owner
Obiagba Mary Ifeoma
Loves to build cool projects 😃
Obiagba Mary Ifeoma
This is a full-stack exercise tracker web application built using the MERN (MongoDB, ExpressJS, ReactJS, NodeJS) stack. You can easily track your exercises with this Full-Stack Web Application.

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

WMouton 2 Dec 25, 2021
A boilerplate for ExpressJs projects configured with ESLint, Prettier & Airbnb Setup. The boilerplate utilises RESTful architecture and uses Mongodb.

ExpressJs-Boilerplate An ExpressJs boilerplate configured with ESLint, Prettier & Airbnb Setup. The boilerplate utilises RESTful architecture and uses

Hammas bin Farrukh 4 Mar 8, 2023
Role based authentication for NodeJS and ExpressJS

Role based authentication Authentication service made for ExpressJS and MongoDB using JWT. We tried to make it as clean and structured as possible. We

null 4 Oct 3, 2021
Pim 4 Jun 21, 2022
Simple auth application with ExpressJS.

NodeJS JWT Authentication sample This is a NodeJS API that supports username and password authentication with JWTs. Available APIs User APIs POST /reg

Yacine Maouche 3 Nov 2, 2022
A developer directory built on Next.js and MongoDB Atlas, deployed on Vercel with the Vercel + MongoDB integration.

MongoDB Starter – Developer Directory A developer directory built on Next.js and MongoDB Atlas, deployed on Vercel with the Vercel + MongoDB integrati

Vercel 246 Dec 20, 2022
Mongo Strict is a TypeScript based smart MongoDB ORM, It makes the usage of MongoDB safer, easier and faster with a better performance...

mongo-strict mongo-strict is compatible with mongo >= 5 Mongo Strict is a TypeScript-based smart MongoDB ORM, It makes the usage of MongoDB safer, eas

Mohamed Kamel 4 Sep 22, 2022
API em NodeJS, utilizando banco de dados MongoDB (TypeORM), com cobertura de testes (coverages), utilizando o Jest

Api Backend Tindin Sobre API em NodeJS, utilizando banco de dados MongoDB (TypeORM), com cobertura de testes (coverages), utilizando o Jest. ?? app ur

Enéas Almeida 1 Jan 20, 2022
API Bate Papo UOL - A backend application developed using NodeJS and mongoDB

BatePapoUOL BackEnd My first backend project! Building an API to the most used brazillian chat app ages ago - Bate Papo UOL! Table of Contents Overvie

Lucas Azzolini Vieira 8 Apr 13, 2022
Uma Api dos 151 primeiros pokemons utilizando NodeJS, Typescript, Docker, MongoDB e Mongoose.

Pokedex API Tópicos Preview Sobre o Pokedex Api Tecnologias Instalação e uso Preview Clique aqui para ter acesso a um preview da Api. Sobre o Pokedex

Marlon Lacerda 3 Nov 27, 2022