Interface Document of Page Metadata

Interface Overview

The interface is used to retrieve metadata information of the corresponding page according to the page path (URI), helping Next.js dynamic routing to determine which specific backend interface should be requested.

Interface Address

{域名地址}/api/metadata

Description:{域名地址}Replace it with your domain name, such ashttps://en.anqicms.com/api/metadata

Request Syntax

GET {域名地址}/api/metadata

Request Headers

This interface also involves common request headers. For more information, please refer toCommon Request Headers (Common Request Headers).

Request parameters

Query Parameters

Parameter Name Type Required description Example
path string Is page path for metadata retrieval /collections/full-length-catsuit.html

response format

JSON

Response Example

{
    "code": 0,
    "data": {
        "title": "Full-Length Catsuit",
        "keywords": "",
        "description": "",
        "image": "https://en.anqicms.com/uploads/202601/05/155e089bfb3dda0b.jpg",
        "nav_bar": 13,
        "page_id": 56,
        "module_id": 2,
        "page_name": "archiveDetail",
        "canonical_url": "https://en.anqicms.com/collections/full-length-catsuit.html",
        "total_pages": 0,
        "current_page": 0,
        "status_code": 200,
        "params": {
            "": "",
            "combine": "",
            "filename": "full-length-catsuit",
            "match": "archive",
            "module": "collections",
            "page": "",
            "pattern": "^([^\/]+?)\/([^\/]+?)(\/c\\-([^\/]+?))?(_([\\d]+))?\\.html$",
            "route": "collections/full-length-catsuit.html"
        }
    },
    "msg": ""
}

Response Field Description

Top Level Field

Field name Type description
code Integer Response Status Code, 0 means success
data object Page metadata object
msg string Response message, empty string when successful

Data field description

Field name Type description
Title string Page title
keywords string Page keywords
description string Page Description
Image string Main Image URL
Nav Bar Integer Navigation Bar ID
page_id Integer Page ID
module_id Integer Module ID
page_name string Page name (used to identify page type)
canonical_url string Standard URL
total_pages Integer Total number of pages (for pagination)
current_page Integer Current page number
status code Integer HTTP status code
params object path parsing parameters

params field description

Field name Type description
filename string Filename (extracted from path)
match string Matching type (e.g., 'archive' indicates an archive page)
module string Module name (such as 'collections' indicates a product collection
pattern string Regular expression for matching paths
route string Original route path

Page Type Description

Based onpage_nameThe value of the field can determine the type of the page, thus deciding the subsequent data request:

page_name Page Type Description
archiveDetail detail page Product Category or Collection Detail Page
archive list list page product category or collection list page
archive index model cover page product category or collection cover page
page detail single page independent page (such as about us)
user detail user detail page user detail page
tag index Tag List Page Tag List Page
tag Tag Details Tag detail page
comments Comment List Comment list page
Guestbook Message page Message page
Index Home Home page
Search Search Page Search

Usage Example

Using Next.js Dynamic Routing

// pages/[...slug].js
import { useRouter } from 'next/router'

export async function getServerSideProps(context) {
  const { slug } = context.params
  const path = '/' + slug.join('/')
  
  // 调用元数据接口
  const res = await fetch(`https://en.anqicms.com/api/metadata?path=${path}`)
  const metadata = await res.json()
  
  // 根据page_name决定后续请求
  const pageName = metadata.data.page_name
  let apiEndpoint = ''
  
  switch(pageName) {
    case 'archiveDetail':
      apiEndpoint = `/api/collection/${metadata.data.params.filename}`
      break
    case 'pageDetail':
      apiEndpoint = `/api/page/${metadata.data.page_id}`
      break
    // ... 其他页面类型
  }
  
  // 调用对应的后端接口获取页面数据
  // const data = await fetch(apiEndpoint)
  
  return {
    props: {
      metadata: metadata.data,
      // pageData: data
    }
  }
}

Error Handling

The API may return the following status codes:

  • 0: Request successful

Points to note

  1. The path parameter must start with a slash(/)
  2. The interface is mainly used for Next.js server-side rendering (SSR) scenarios
  3. Can be based onpage_nameThe value of the field determines the page type, thereby determining the subsequent data request interface
  4. paramsfields inmoduleandfilenameCan be used to build specific API request paths