In website operation, we often need to dynamically retrieve and display the articles or product details of the site.AnQiCMS (AnQiCMS) provides a powerful and flexible API interface, making this process very convenient.Among them, the interface for obtaining document details is one of the core ones, which can not only return the basic information of the document but also allow you to easily obtain the complete content of the article.

This article will guide you on how to accurately extract the complete content of the document from the document detail interface of Anqi CMS.

Call the document detail interface to get data

To extract the full content of the document, we first need to send a request to the document detail interface of Anqi CMS. The address of this interface is{域名地址}/api/archive/detailand useGETmethod to call.

When initiating a request, you need to provide the unique identifier of the document. Typically, this will be the document'sID, or the document'sURL 别名(filename)Either one of these is okay. For example, if you know the ID of an article is1you can do something likeGET {域名地址}/api/archive/detail?id=1Make a request in this manner. Usually, these IDs or aliases can be obtained from the document list interface(/api/archive/list)or directly from the website's URL.

After you successfully initiate the request, the interface will return a JSON-formatted data. This data structure is clear, containing various detailed information of the document.

Locate the full content of the document from the returned data

After successfully obtaining the JSON response, the next step is to locate the full content of the document we are concerned about. The returned JSON data will containcode/msganddataThree top-level fields. Among them,datathe field is our focus, carrying all the details about the document.

Let's look at a typical successful return data example:

{
  "code": 0,
  "data": {
    "id": 1,
    "created_time": 1607308159,
    "updated_time": 1662717106,
    "title": "欢迎使用AnqiCMS",
    // ... 其他文档元数据 ...
    "category": {
      // ... 分类信息 ...
    },
    "data": { // 这个是关键!
      "id": 1,
      "content": "<p>欢迎使用AnqiCMS</p>" // 文档的完整内容就在这里
    },
    // ... 其他字段 ...
  },
  "msg": ""
}

From this structure, we can clearly see that the complete content of the document is hidden in onenesteddatafield. The specific path is: top-level responsedataobject underdatafield(yes, there are two}data), inside it is namedcontentfield.

So, if you are using a programming language to process this JSON response, you would typically access it like this:response.data.data.content.

ThiscontentThe field is typically an HTML string that includes the text, images, links, and other rich media information of the document.The Anqi CMS allows you to use rich text format when editing articles in the backend editor, so returning HTML is expected here and can be directly used for front-end page rendering.

Practical tips and注意事项 after extracting the content

After obtaining the complete content of the document, you can use it in various scenarios:

  • Front-end display:The most direct use is to render these HTML contents to your webpage, mini-program, or mobile application to display the full article details.Most modern frontend frameworks support rendering HTML strings directly.
  • Content cleaning and security:Although AnQi CMS performs some processing when generating content, as a matter of practice, when you directly render HTML content obtained from the API on the front-end page, it is recommended that you use an appropriate HTML sanitization library or method to prevent potential XSS (cross-site scripting) attacks or other security vulnerabilities.For example, in JavaScript, you can use libraries like DOMPurify for cleaning.
  • Combine with other information:At the top leveldataIn the field, in addition to the core content, you can also findtitle(Document Title),description(Document summary),keywords(Keywords),logo(Document logo) andextra(Custom field) and other information. These metadata should be combined with the completecontentto provide users with a richer and more comprehensive reading experience.
  • SEO optimization:Extracted title, description, and keywords information, which can be used to generate page content.<title>tags,metaDescription and keyword tags, helpful for improving search engine optimization.
  • In-site search or data analysis:If you need to build an in-site search function, you can extract the text content of thecontentfield as index data. Similarly, analyzing the document content can also provide valuable insights.

Through the document detail interface, Anqi CMS makes it simple and efficient to obtain the core content of the document.If you understand the data structure, you can flexibly use this information to build powerful and rich websites or applications.


Frequently Asked Questions (FAQ)

1. WhycontentThe field returns HTML format instead of plain text?The Anqi CMS backend editor supports rich text editing, allowing you to insert images, links, set styles, and more.Therefore, the interface will return the content in HTML format to fully present the style and structure of the document you created in the background.If you only need plain text, you need to parse and remove tags from the HTML string on the client side.

2. BesidescontentWhat useful information can the document detail interface provide?In addition to the core content, what top-level information does the interface return?dataThe object also includes the document'sid/title/seo_title/keywords/description/views(Views),comment_count(Comments),images(Group photos),logo(thumbnail),created_time(Publication time) and rich information. Moreover, if your model has set custom fields, their contents will also be displayed inextraReturn within the object.

3. If the document is paid or password-protected, can I still get it directly?content?For paid documents, you need to go through/api/archive/order/checkThe interface checks if the user has paid; for password-protected documents, it is necessary to pass through/api/archive/password/checkAPI verification password. Only after verification is passed will the returned data of these APIs contain the complete content of the documents, or allow you to continue callingarchiveDetailAPI to retrieve complete content. Call directlyarchiveDetailInterfaces usually do not return paid or password-protected documents.contentfield.