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 Contentstoc

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 headerAuthorization: {token} or cookieBLOG_NOW_TOKEN={token}

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

Public response data

type:application/json

nametypeexampledescription
codenumber200HTTP status
messagestring"ok"-
bodyany{ "post": {...} }Response body
errorany?{ "mongoError": {...} }Error info

errors

  • 401 Unauthorized Login required
  • 403 Forbidden Permision denied

User

Endpoint:/user/:CONTROLLER/:SCOPE

Register

POST /user/auth/register

data

nametyperequireddescription
usernamestring✔️More than 5 characters
passwordstring✔️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

nametyperequireddescription
usernamestring✔️More than 5 characters
passwordstring✔️More than 5 characters

response body

nametypeexampledescription
tokenstring-Personal token
profileUserProfile{ "uuid": "...", ... }Personal profile data

Personal profile ❗

GET /user/auth/profile

params

-

response body

nametypeexampledescription
profileUserProfile{ "uuid": "...", ... }Personal profile data
profile.authoritynumber1Number between 0-4
profile.avatarstring-Avatar URL
profile.created_atstring-Date string
profile.emailstring-Personal email
profile.gender"male" | "female" | "other"-Gender
profile.nicknamestring--
profile.sloganstring--
profile.titlestring-Special title
profile.uidnumber12345Number more than 10000
profile.usernamestring-User name
profile.uuidstring-UUID

Post

Get post data

GET /post/:CONTROLLER/:SCOPE

params

nametyperequireddescription
:CONTROLLER"uuid" | "pid" | "slug"✔️Filter controller
:SCOPEstring✔️Filter scope

response body

nametypeexampledescription
postPostData-Post data
post.author_uuidstring-User UUID
post.contentstring"Hello, world. This is my post!"Post raw content
post.created_atstring"2021-10-09T13:37:51.220Z"Date string
post.edited_atstring?-Date string
post.editor_uuidstring?-Mdifier user UUID
post.pidposInt"123"Number more than 1
post.slugstring?"hello-world"Slug
post.titlestring"Hello, world"Post title
post.uuidstring"f6b72355-9864-4115-95c0-7b75a"Post UUID

Get recent posts list

GET /post/list/recent

params

nametyperequireddescription
limitnumberNumber between 1-25
offsetnumberNumber more than 0

response body

nametypeexampledescription
postsPostData[]-List of post data

Submit new post ‼️

POST /post/new

Alias:/post/create

data

nametyperequireddescription
titlestring✔️Post display title
contentstringPost raw content (markdown)
slugstringPost slug

response body

nametypeexampledescription
uuidstring-Post UUID

errors

  • 409 Conflict Slug conflict

Update post ‼️

PATCH /post/:CONTROLLER/:SCOPE

data

nametyperequireddescription
:CONTROLLER"uuid" | "pid" | "slug"✔️Filter controller
:SCOPEstring✔️Filter scope
titlestringPost display title
contentstringPost raw content (markdown)
slugstringPost slug

response body

Nothing special

errors

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