Code Monkey home page Code Monkey logo

alt_school_exam's Introduction

Backend NodeJS Second Semester Examination Project

This is a typical server with Endpoints for a typical Blogging Application. Hence called the Blog API Project...


Requirements

  1. Users can register
  2. User can login with Passport using JWT
  3. Basic Authentication for Logged in user and Authorization for Bloggers owners are set up.
  4. Users(Logged in & not logged in) can retrieve blog(s)
  5. Logged in users can create blogs
  6. Authorized bloggers should be able to update and delete blog(s)
  7. Test application

Setup

  • Install NodeJS, mongodb
  • pull this repo
  • Run npm install to install needful dependencies.
  • update env with example.env
  • run npm start to kickstart application

Base URL

Models


User

field data_type constraints
id string required
username string optional
first_name string required
last_name string required
email string required
password string required

Blog

field data_type constraints
id string required
created_at date required
state string required, enum: ['draft', 'published']
title number required
reading_time number required
read_count number required
tags string required
author id required
body string required, enum:

APIs


Signup User

  • Route: /api/auth/signup
  • Method: POST
  • Body:
{
  "email": "[email protected]",
  "password": "Password1",
  "first_name": "jon",
  "last_name": "doe",
  "username": 'jon_doe",
}
  • Responses

Success

{
    message: 'Signup successful',
    user: {
        "email": "[email protected]",
        "password": "Password1",
        "first_name": "jon",
        "last_name": "doe",
        "username": 'jon_doe",
    },
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiNjM2Njg0OGIzNGQ4OTIzYjA1NjM5NjJkIiwiZW1haWwiOiJheW9sdXdhbWlyYWNsZUBnbWFpbC5jb20ifSwiaWF0IjoxNjY3NjYyOTg5LCJleHAiOjE2Njc2NjY1ODl9.YPoI35Y5oJqdmIRBTWOm8scFR7sDDhCav-Fw8VFaqX8"
}

Login User

  • Route: /api/auth/signin
  • Method: POST
  • Body:
{
  "password": "Password1",
  "username": 'jon_doe",
}
  • Responses

Success

{
    message: 'Login successful',
    token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiNjM2Njg0OGIzNGQ4OTIzYjA1NjM5NjJkIiwiZW1haWwiOiJheW9sdXdhbWlyYWNsZUBnbWFpbC5jb20ifSwiaWF0IjoxNjY3NjYyOTg5LCJleHAiOjE2Njc2NjY1ODl9.YPoI35Y5oJqdmIRBTWOm8scFR7sDDhCav-Fw8VFaqX8'
}

Create Blog

  • Route: /api/blog/create
  • Method: POST
  • Header
    • Authorization: Bearer {token}
  • Body:
{
       title: "The King's Horseman",
      "description": "A tale by moonlight prose.",
      "blog": "Once upon a time...",
      "tags": "fiction"
}
  • Responses

Success

{
    status: "success,
    msg: "Blog successfully created...",
    blog: {
      _id: "635fd42952267b47b3f6e0c9",
      title: "The King's Horseman",
      "description": "A tale by moonlight prose.",
      "author": [
        {
          "_id": "5fd42952267b47b3f69499",
          "email: "[email protected]",
          "password": "$2b$10\$tddpO5TKboEOEQaOsL9ytOjF14HwmT95IWlC3eSiKFJ7uizJI9GX6",
          "first_name":"John",
          "last_name": "Doe",
          "username" : "johnnydoe"
        }
      ]
      "state": "published",
      "read_count": 1,
      "reading_time": "4"
      "createdAt": "2022-11-02T13:27:00.984Z",
      "updatedAt": "2022-11-05T15:43:56.005Z",
      "__v": 0
    }
    total_price: 900,
    created_at: Mon Oct 31 2022 08:35:00 GMT+0100,
}



Get Single Blog

  • Route: /api/blog/:id
  • Method: GET
  • Header
    • Authorization: Bearer {token}
  • Responses

Success

{
    status: "success,
    msg: "Blog successfully retrieved",
    blog: {
      _id: "635fd42952267b47b3f6e0c9",
      title: "The King's Horseman",
      "description": "A tale by moonlight prose.",
      "author": [
        {
          "_id": "5fd42952267b47b3f69499",
          "email: "[email protected]",
          "password": "$2b$10\$tddpO5TKboEOEQaOsL9ytOjF14HwmT95IWlC3eSiKFJ7uizJI9GX6",
          "first_name":"John",
          "last_name": "Doe",
          "username" : "johnnydoe"
        }
      ]
      "state": "published",
      "read_count": 1,
      "reading_time": "4"
      "createdAt": "2022-11-02T13:27:00.984Z",
      "updatedAt": "2022-11-05T15:43:56.005Z",
      "__v": 0
    }
    total_price: 900,
    created_at: Mon Oct 31 2022 08:35:00 GMT+0100,
}

Author updates their Blog

Only authors who create their blogs are authorized here...

  • Route: /api/blog/update/:id
  • Method: PUT
  • Header
    • Authorization: Bearer {token}
  • Responses

{ status: "success, msg: "Blog successfully updated...", blog: { _id: "635fd42952267b47b3f6e0c9", title: "The King's Horseman", "description": "A tale by moonlight prose.", "author": [ { "_id": "5fd42952267b47b3f69499", "email: "[email protected]", "password": "$2b$10$tddpO5TKboEOEQaOsL9ytOjF14HwmT95IWlC3eSiKFJ7uizJI9GX6", "first_name":"John", "last_name": "Doe", "username" : "johnnydoe" } ] "state": "published", "read_count": 1, "reading_time": "4" "createdAt": "2022-11-02T13:27:00.984Z", "updatedAt": "2022-11-05T15:43:56.005Z", "__v": 0 } total_price: 900, created_at: Mon Oct 31 2022 08:35:00 GMT+0100, }


Author gets their Blogs

Only authors who create their blogs are authorized here...

  • Route: /api/blog/author/blogs
  • Method: GET
  • Header
    • Authorization: Bearer {token}
  • Responses

Success

{
    "status": "success",
     "msg": "All authors blogs successfully retrieved...",
    data: [ all blog data]
}

Get Blogs

  • Route: /api/blog/all
  • Method: GET
  • Header:
    • Authorization: Bearer {token}
  • Query params:
    • page (default: 1)
    • per_page (default: 20)
    • order_by_timestamp (default: created_at)
    • order_by_read_count(default: read_count)
    • order_by_reading_time (default: reading_time)
    • search_by_author(default: authorName)
    • search_by_title(default: blogTitle)
    • search_by_tags(default: tags)
    • created_at
  • Responses

Success

{
    "status": "success",
     "msg": "All blogs successfully retrieved...",
    data: [ all blog data]
}

  • Route: /api/delete/:id
  • Method: DELETE
  • Header:
  • Authorization: Bearer {token}

{ "status": "success", "msg": "Blog with the id of 'id' has been successfully deleted...",

}


...

Contributor

  • Ayooluwa Adeleke

StudentID

  • ALT/SOE/022/1367

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.