Skip to content

BlogNow API References

机智的小鱼君 edited this page Oct 11, 2021 · 2 revisions

API endpoint: /api

e.g. https://blog-now.vercel.app/api

Table of Contents toc

Authorization

The endpoints marked ❗ require login.

The endpoints marked ‼️ may need auth level higher than 1.

Get the personal token from /user/auth/sign-in API.

Request with header Authorization: {token} or cookie BLOG_NOW_TOKEN={token}

The token will expire 7 days after the last valid request.

Public response data

type: application/json

name type example description
code number 200 HTTP status
message string "ok" -
body any { "post": {...} } Response body
error any? { "mongoError": {...} } Error info

errors

  • 401 Unauthorized Login required
  • 403 Forbidden Permision denied

User

Endpoint: /user/:CONTROLLER/:SCOPE

Register

POST /user/auth/register

data

name type required description
username string ✔️ More than 5 characters
password string ✔️ More than 5 characters

response body

Nothing special

errors

  • 400 Bad Request Username or password is too short
  • 409 Conflict Requested username is already in use

Sign-in

POST /user/auth/sign-in

Alias: /user/auth/login

data

name type required description
username string ✔️ More than 5 characters
password string ✔️ More than 5 characters

response body

name type example description
token string - Personal token
profile UserProfile { "uuid": "...", ... } Personal profile data

Personal profile ❗

GET /user/auth/profile

params

-

response body

name type example description
profile UserProfile { "uuid": "...", ... } Personal profile data
profile.authority number 1 Number between 0-4
profile.avatar string - Avatar URL
profile.created_at string - Date string
profile.email string - Personal email
profile.gender "male" | "female" | "other" - Gender
profile.nickname string - -
profile.slogan string - -
profile.title string - Special title
profile.uid number 12345 Number more than 10000
profile.username string - User name
profile.uuid string - UUID

Post

Get post data

GET /post/:CONTROLLER/:SCOPE

params

name type required description
:CONTROLLER "uuid" | "pid" | "slug" ✔️ Filter controller
:SCOPE string ✔️ Filter scope

response body

name type example description
post PostData - Post data
post.author_uuid string - User UUID
post.content string "Hello, world. This is my post!" Post raw content
post.created_at string "2021-10-09T13:37:51.220Z" Date string
post.edited_at string? - Date string
post.editor_uuid string? - Mdifier user UUID
post.pid posInt "123" Number more than 1
post.slug string? "hello-world" Slug
post.title string "Hello, world" Post title
post.uuid string "f6b72355-9864-4115-95c0-7b75a" Post UUID

Get recent posts list

GET /post/list/recent

params

name type required description
limit number Number between 1-25
offset number Number more than 0

response body

name type example description
posts PostData[] - List of post data

Submit new post ‼️

POST /post/new

Alias: /post/create

data

name type required description
title string ✔️ Post display title
content string Post raw content (markdown)
slug string Post slug

response body

name type example description
uuid string - Post UUID

errors

  • 409 Conflict Slug conflict

Update post ‼️

PATCH /post/:CONTROLLER/:SCOPE

data

name type required description
:CONTROLLER "uuid" | "pid" | "slug" ✔️ Filter controller
:SCOPE string ✔️ Filter scope
title string Post display title
content string Post raw content (markdown)
slug string Post slug

response body

Nothing special

errors

  • 404 Not Found The specified post was not found
  • 409 Conflict Slug conflict