Nine, Blog Site API Call Example

Let's analyze the pages of the blog site first, and then decompose the interfaces required for each page.

9.1 Blog site page structure analysis

Typical blog sites usually contain the following pages:

9.1.1 Main page types

  • Home- Show the latest articles, popular articles, recommended articles, etc.
  • Category Page- Show articles list by category
  • Tab page- Show articles list by tag
  • Article detail page- Show detailed content of a single article
  • Archive page- Display articles by time archive
  • Search Page- Search results page
  • About page- Single page content
  • User-related pages- Login, registration, personal center, etc.

9.2 Detailed description of the required API interfaces for each page

9.2.1 Home page

The home page is the most important page of the blog, usually containing a variety of content displays.

Main interface call:

  1. Get article list(/api/archive/list)

    {
     "limit": 10,
     "page": 1,
     "order": "created_time desc"
    }
    
    • Purpose: Get the latest article list
    • Parameters: limit (number of items per page), page (page number), order (sort method)
  2. Get recommended articles(/api/archive/list)

    {
     "flag": "c",  // 推荐文章
     "limit": 5
    }
    
    • Purpose: Get the list of recommended articles
    • Parameters: flag(recommendation identifier), limit(number)
  3. Get popular articles(/api/archive/list)

    {
     "order": "views desc",
     "limit": 5
    }
    
    • Purpose: Get the articles with the highest click-through rate
    • Parameters: order(By view count sorting), limit(Quantity)
  4. Get category list(/api/category/list)

    {
     "limit": 10
    }
    
    • Purpose: Get all categories for navigation menu
  5. Get tag list(/api/tag/list)

    {
     "type": "list",
     "limit": 20
    }
    
    • Purpose: Get hot tags for tag cloud
  6. Get System Settings(/api/setting/system)

    • Purpose: Get the title, description, keywords and other basic information of the website
  7. Get Home Page Settings(/api/setting/index)

    • Purpose: Get the specific configuration information of the homepage
  8. Get navigation list(/api/nav/list)

    • Purpose: Get the website navigation menu
  9. Get Banner list(/api/banner/list)

    • Purpose: Get the homepage carousel image

9.2.2 Category page

The category page displays the list of articles under a specific category.

Main interface call:

  1. Get category details(/api/category/detail)

    {
     "id": 1
    }
    
    • Purpose: Get the current category information
    • Parameter: id (category ID) or filename (category alias)
  2. Get the list of articles under the category(/api/archive/list)

    {
     "categoryId": 1,
     "limit": 10,
     "page": 1
    }
    
    • Purpose: Get the list of articles under the category
    • Parameters: categoryId (Category ID), limit (Number of items per page), page (Page number)
  3. Get the list of subcategories(/api/category/list)

    {
     "parentId": 1,
     "limit": 10
    }
    
    • Purpose: Get the subcategories of the current category
    • Parameter: parentId (Parent Category ID)
  4. Get System Settings(/api/setting/system)

    • Purpose: Get basic website information
  5. Get category list(/api/category/list)

    • Purpose: Get all categories, used for sidebar navigation

9.2.3 Tag Page

Display a list of articles under a specific tag on the tag page.

Main interface call:

  1. Get tag details(/api/tag/detail)

    {
     "id": 1
    }
    
    • Purpose: Get the current tag information
    • Parameters: id (tag ID) or name (tag name)
  2. Get article list under tag(/api/tag/data/list)

    {
     "id": 1,
     "limit": 10,
     "page": 1
    }
    
    • Purpose: Get the article list under the tag
    • Parameters: tagId(Tag ID), limit(Quantity per page), page(Page number)
  3. Get tag list(/api/tag/list)

    {
     "type": "list",
     "limit": 20
    }
    
    • Purpose: Get popular tags for related tag recommendations
  4. Get System Settings(/api/setting/system)

    • Purpose: Get basic website information

9.2.4 Article detail page

The article detail page displays the complete content of a single article.

Main interface call:

  1. Get article details(/api/archive/detail)

    {
     "id": 1
    }
    
    • Purpose: Get article detailed content
    • Parameter: id (article ID) or filename (article alias)
  2. Get article parameters(/api/archive/params)

    {
     "id": 1,
     "sorted": true
    }
    
    • Purpose: Get custom article parameters
    • Parameter: id(article ID), sorted(return format)
  3. Get previous document(/api/archive/prev)

    {
     "id": 1
    }
    
    • Purpose: Get the previous article information
  4. Get next document(/api/archive/next)

    {
     "id": 1
    }
    
    • Purpose: Get the next article information
  5. Get related articles(/api/archive/list)

    {
     "type": "related",
     "limit": 5,
     "id": 1
    }
    
    • Purpose: Get other articles in the same category
    • Parameters: type="related" (type of related documents), limit (quantity), id (current article)
  6. Get Comment List(/api/comment/list)

    {
     "archive_id": 1,
     "limit": 10,
     "page": 1
    }
    
    • Purpose: Retrieve article comment list
    • Parameters: archive_id (article ID), limit (number of items per page), page (page number)
  7. Check collection status(/api/favorite/check)

    {
     "archive_id": 1
    }
    
    • Purpose: Check if the current user has favorited this article
    • Authentication required
  8. Get System Settings(/api/setting/system)

    • Purpose: Get basic website information

9.2.5 Search page

The search page displays articles related to the search keywords.

Main interface call:

  1. Search article list(/api/archive/list)

    {
     "q": "关键词",
     "limit": 10,
     "page": 1
    }
    
    • Purpose: Search articles containing keywords
    • Parameters: q(search keywords), limit(number of items per page), page(page number)
  2. Get hot search(/api/archive/list)

    {
     "order": "views desc",
     "limit": 10
    }
    
    • Purpose: Get popular search content
  3. Get search suggestions(/api/archive/list)

    {
     "q": "关键词前缀",
     "limit": 5
    }
    
    • Purpose: Get search suggestions
  4. Get System Settings(/api/setting/system)

    • Purpose: Get basic website information

9.2.6 About the page

Single-page content display.

Main interface call:

  1. Get page details(/api/page/detail)

    {
     "id": 1
    }
    
    • Purpose: Get single page content
    • Parameter: id (page ID) or filename (page alias)
  2. Get System Settings(/api/setting/system)

    • Purpose: Get basic website information

9.2.7 User-related pages

9.2.7.1 Login Page

Main interface call:

  1. User Login(/api/login)
    
    {
     "user_name": "用户名",
     "password": "密码"
    }
    
    • Purpose: User Login Authentication
    • Parameters: user_name (username), password (password), email (email), phone (phone number)
9.2.7.2 Registration Page

Main interface call:

  1. User Registration(/api/register)

    {
     "user_name": "用户名",
     "password": "密码",
     "email": "邮箱",
     "captcha": "验证码"
    }
    
    • Purpose: New User Registration
    • Parameters: user_name (Username), password (Password), email (Email), captcha (Captcha)
  2. Get verification code(/api/captcha)

    • Use: Get image verification code
  3. Send email verification(/api/verify/email)

    {
     "email": "邮箱地址"
    }
    
    • Use: Send email verification code
9.2.7.3 Personal Center Page

Main interface call:

  1. Get user details(/api/user/detail)

    • Use: Get current user details
    • Authentication required
  2. Get user favorite list(/api/favorite/list)

    {
     "limit": 10,
     "page": 1
    }
    
    • Purpose: Retrieve the list of articles favorited by the user
    • Authentication required
  3. Retrieve the list of comments made by the user(/api/comment/list)

    {
     "user_id": 1,
     "limit": 10,
     "page": 1
    }
    
    • Purpose: Retrieve the comments posted by the user
    • Authentication required
  4. Update user information(/api/user/update)

    {
     "nickname": "昵称",
     "email": "邮箱"
    }
    
    • Purpose: Update user information
    • Authentication required
  5. Update user avatar(/api/user/avatar)

    • Purpose: Update user avatar
    • Authentication required

9.3 Page Loading Process Example

For example, with the article detail page, explain the complete API call process:

9.3.1 Page Initialization

  1. Get article details
  2. Increase article views (via subsequent requests or server-side processing)
  3. Get article parameters

9.3.2 Sidebar content loading

  1. Get previous/next article
  2. Get related article recommendations
  3. Get the list of popular articles

9.3.3 Load the comment area

  1. Get Comment List
  2. If the user is logged in, get the user's collection status for the current article

9.3.4 Interactive function

  1. Post Comment (requires authentication)
  2. Favorite/Unfavorite (requires authentication)
  3. Like Comment (requires authentication)

9.4 Common Page Combination Calls

9.4.1 Home + Category Page Combination

// 并行请求多个接口
Promise.all([
  fetch('/api/archive/list', { params: { limit: 10, page: 1 } }),
  fetch('/api/category/list', { params: { limit: 10 } }),
  fetch('/api/tag/list', { params: { type: 'list', limit: 20 } }),
  fetch('/api/setting/system')
]).then(responses => {
  // 处理所有响应数据
  const [articles, categories, tags, settings] = responses;
  // 渲染页面
});

9.4.2 Full Call of Article Detail Page

// 串行或并行调用多个接口
const articleId = 1;
Promise.all([
  fetch(`/api/archive/detail`, { params: { id: articleId } }),
  fetch(`/api/archive/params`, { params: { id: articleId } }),
  fetch(`/api/archive/prev`, { params: { id: articleId } }),
  fetch(`/api/archive/next`, { params: { id: articleId } }),
  fetch(`/api/comment/list`, { params: { archive_id: articleId, limit: 10 } }),
  fetch(`/api/setting/system`)
]).then(responses => {
  const [article, params, prev, next, comments, settings] = responses;
  // 组合数据并渲染页面
});

It can be seen that a complete blog site needs to call multiple API interfaces to build various pages, developers can choose the appropriate interface combination according to actual needs to realize rich blog functions.