Blogospot (Blog API)

samuelume

Samuel Ume

Posted on January 10, 2023

Blogospot (Blog API)

Blogospot is a RESTful blog API. Users of the Blogospot RESTful API can create, modify, publish, and remove blogs as well as access a list of all blogs that have already been published. JWT (Jason Web Token) is used by the API for authentication and authorization to give consumers privacy and security. We'll cover a brief overview of how to get started with the blog API in this article


prerequisites

  • Javascript
  • Node js
  • MongoDb

Requirements

Users must have the following fields:

  • first_name
  • second_name
  • email
  • password

A logged in user will be able to:

  • Sign up and sign in to the blog app
  • View a list of published blogs
  • View a single published blog
  • Create a blog (in draft state)
  • Update the state of a blog to published (if the user is the owner of the blog)
  • Edit a blog in draft or published state (if the user is the owner of the blog)
  • Delete a blog in draft or published state (if the user is the owner of the blog)
  • View a list of their own blogs

A blog may contain the following fields:

  • title
  • description
  • tags
  • author (user)
  • timestamp
  • state (either "draft" or "published")
  • read_count
  • reading_time
  • body

The list of published blogs that can be accessed by both logged in and not logged in users must be:

  • Paginated (default of 20 blogs per page)
  • Searchable by author, title, and tags
  • Orderable reading_time, and timestamp

Development

Base URL

The base URL for the api is https://misty-cowboy-hat-crow.cyclic.app/

Models


User

field data_type constraints
id string required
username string required, unique
firs_tname string required
last_name string required
email string required, unique
password string required

Blog

field data_type constraints
title string required, unique
description string optional
author ref - User
state string required, default: 'draft', enum: ['draft', 'published']
read_count Number default: 0
reading_time Number
tags array optional
body string required

APIs

Creating a user

  • Route : /api/v1/signup

  • Mthod : POST

๐Ÿ‘‡ Body

{
  "first_name": "firstName",
  "last_name": "secondName",
  "username": "username",
  "email": "email@gmail.com",
  "password": "1234567"
}
Enter fullscreen mode Exit fullscreen mode

๐Ÿ‘‡ Response

{
    "status": true,
    "data": {
        "first_name": "firstName",
        "last_name": "secondName",
        "username": "username",
        "email": "email@gmail.com",
        "_id": "63bd099a16b1654c5a842c8c",
        "__v": 0

}
Enter fullscreen mode Exit fullscreen mode

Login a user

  • Route : /api/v1/login

  • Mthod : POST

๐Ÿ‘‡ Body

{
  "email": "email@gmail.com",
  "password": "1234567"
}
Enter fullscreen mode Exit fullscreen mode

๐Ÿ‘‡ Response

{
    "status": true,
    "data": {
        "first_name": "firstName",
        "last_name": "secondName",
        "username": "username",
        "email": "email@gmail.com",
        "_id": "63bd099a16b1654c5a842c8c",
}
Enter fullscreen mode Exit fullscreen mode

Create Blog

  • Route: api/v1/blogospot/blogs
  • Method: POST
  • Header
    • Authorization: cookie {token}

๐Ÿ‘‡ Body

{
  "title": "List",
  "description": "PoliticsVerse  @PoliticsVerse ยท 6h LiCompanies who hav",

  "tags": ["Airlines", "America"],
  "state": "published",
  "body": "Skip to comments.\r\nList twiter ^Posted on 11/05/2022 1:45:38 PM PDT by janetjanet998\r\nPoliticsVerse @PoliticsVerse ยท 6h List of Companies who have suspended Twitter Ads: \r\nGeneral Mills CVS United Aiโ€ฆ [+1616 chars]"
}
Enter fullscreen mode Exit fullscreen mode

๐Ÿ‘‡ Response

{
  "status": "true",
  "data": {
    "title": "List",
    "description": "PoliticsVerse  @PoliticsVerse ยท 6h LiCompanies who hav",
    "author": "6367c296ba7522bd8561e4f6",
    "state": "draft",
    "read_count": 0,
    "tags": ["Airlines", "America"],
    "body": "Skip to comments.\r\nList twiter ^Posted on 11/05/ 2022 1:45:38 PM PDT by janetjanet998\r\nPoliticsVerse @PoliticsVerse ยท 6h List of Companies who have suspended Twitter Ads: \r\nGeneral Mills CVS United Aiโ€ฆ [+1616 chars]",
    "_id": "6367cc2271c384885108032f",
    "createdAt": "2022-11-06T15:00:50.202Z",
    "updatedAt": "2022-11-06T15:00:50.202Z",
    "reading_time": 2
  }
}
Enter fullscreen mode Exit fullscreen mode

Get all Blogs

  • Route: /api/v1/login/blogospot/blogs
  • Method: get

๐Ÿ‘‡ Body

  • Get all published blogs
  • filter by tags
  • filter by title
  • sort by timestamp
  • sort by reading_time, timestamp

๐Ÿ‘‡ Response

{
  "status": "true",
  "data": {
    "_id": "6367cc2271c384885108032f",
    "title": "The Adventures of John",
    "description": "Fun times as Johnny",
    "author": "6367c296ba7522bd8561e4f6",
    "state": "published",
    "read_count": 0,
    "tags": ["memoirs", "expose"],
    "body": "A very fun article that is long enough to be fun, and short enough to be ..fun! A sailor went to sea to see what he could see but all that he could see was the bottom of the deep blue sea.",
    "createdAt": "2022-11-06T15:00:50.202Z",
    "updatedAt": "2022-11-06T16:22:29.326Z",
    "reading_time": 1
  }
}
Enter fullscreen mode Exit fullscreen mode

Blogs by a user

  • Route: /api/v1/login/blogospot/blogs/user

  • Method: get

All blogs created by a specific user

๐Ÿ‘‡ Response

{
  "status": "true",
  "data": {
    "_id": "6367cc2271c384885108032f",
    "title": "The Adventures of John",
    "description": "Fun times as Johnny",
    "author": "6367c296ba7522bd8561e4f6",
    "state": "published",
    "read_count": 0,
    "tags": ["memoirs", "expose"],
    "body": "A very fun article that is long enough to be fun, and short enough to be ..fun! A sailor went to sea to see what he could see but all that he could see was the bottom of the deep blue sea.",
    "createdAt": "2022-11-06T15:00:50.202Z",
    "updatedAt": "2022-11-06T16:22:29.326Z",
    "reading_time": 1
  },
{
    "_id": "6367cc2271c384885108032f",
    "title": "The Adventures of John",
    "description": "Fun times as Johnny",
    "author": "6367c296ba7522bd8561e4f6",
    "state": "published",
    "read_count": 0,
    "tags": ["memoirs", "expose"],
    "body": "A very fun article that is long enough to be fun, and short enough to be ..fun! A sailor went to sea to see what he could see but all that he could see was the bottom of the deep blue sea.",
    "createdAt": "2022-11-06T15:00:50.202Z",
    "updatedAt": "2022-11-06T16:22:29.326Z",
    "reading_time": 1
  }
}
Enter fullscreen mode Exit fullscreen mode

Update the content of a blog

  • Route: api/v1/blogospot/blogs/:id
  • Method: PATCH
  • Header
  • Authorization: cookie{token}
  • Requirement: User must be logged

๐Ÿ‘‡ Body

{
  "state": "published",
  "tags": ["memoirs", "expose"],
  "body": "A very fun article that is long enough to be fun, and short enough to be ..fun! A sailor went to sea to see what he could see but all that he could see was the bottom of the deep blue sea."
}
Enter fullscreen mode Exit fullscreen mode

๐Ÿ‘‡ Response

{
  "status": "true",
  "data": {
    "_id": "6367cc2271c384885108032f",
    "title": "List",
    "description": "PoliticsVerse  @PoliticsVerse ยท 6h LiCompanies who hav",
    "author": "6367c296ba7522bd8561e4f6",
    "state": "published",
    "read_count": 0,
    "tags": ["memoirs", "expose"],
    "body": "A very fun article that is long enough to be fun, and short enough to be ..fun! A sailor went to sea to see what he could see but all that he could see was the bottom of the deep blue sea.",
    "createdAt": "2022-11-06T15:00:50.202Z",
    "updatedAt": "2022-11-06T16:22:29.326Z",
    "reading_time": 1
  }
}
Enter fullscreen mode Exit fullscreen mode

Delete Blog

  • Route: api/v1/blogospot/blogs/:id
  • Method: DELEtE
  • Requirement: User must be llogged in

  • Delete the blog with the specified id, and returns the deleted blog

{
        status: true,
        message: "Deleted successfully"
}
Enter fullscreen mode Exit fullscreen mode

Error handling

  • All error will be returned in this json format
{
  status: false, 
  error: "Error message"
}
Enter fullscreen mode Exit fullscreen mode

Conclusion

I hope this brief article on blogospot API helps you navigate and implement the API for your app easily.

๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
samuelume
Samuel Ume

Posted on January 10, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Blogospot (Blog API)
javascript Blogospot (Blog API)

January 10, 2023

IP Location Grabbing
javascript IP Location Grabbing

May 29, 2022

ยฉ TheLazy.dev

About