When using AnQiCMS to build a website, we often need to obtain detailed information of various documents through the API interface. Among them,archive/detailThe interface is the key to obtaining the details of a single document. Many developers and content operators may be curious about whether the data structure returned by this interface will be different for different types of documents, such as ordinary articles, news, or product information on e-commerce websites.The answer is: it has both unity and high flexibility.
First, AnQi CMS is designedarchive/detailWhen interfacing, a core and unified set of data fields is provided for all document types. Whether you request a regular article or a specific product detail, you will find the returneddataObjects such asid(Document ID),title(Title),seo_title(SEO title),description(Summary),url_token(URL alias),created_time(creation time) andupdated_time(Updated time) and other basic information. These fields constitute the basic framework of the document, ensuring consistency in core properties across different types of content, greatly facilitating the front-end data processing and display logic, allowing you to easily present the common properties of the document.
On this unified structure, AnQi CMS also integrates some fields designed directly for specific document types. A striking example isprice(price) andstock(Inventory quantity). When you get a product document, these fields will appear directly.dataIn the root level, providing you with the pricing and inventory status of the product.And for ordinary articles of this kind that do not require price and inventory attributes, these fields may be displayed as default values (such as 0) or not displayed at all, reflecting the system's direct support for common business scenarios and saving the trouble of redundant configuration in custom fields.
However, the real strength of Anqi CMS lies in its flexible "model" mechanism and its closely relatedextrafield. Each document belongs to a specific "document model" (viamodule_idIdentify), and each model can be configured with a series of custom fields. It is these custom fields that are the key to significant changes in the data structure of different document types. When you go througharchive/detailWhen retrieving the document details, all custom fields configured for the model of the document will be aggregated into the returned data.extrain the object. For example, a technical article may haveextraincludingauthor(Author),version(Version) etc. custom fields, while a product document may containextrainmaterial(Material),color(Color),size(Size) etc. more detailed product parameters.extraThe structure of the field iskey => itemin the form ofkeyIs the name of the custom field,itemthen containsname(field name),value(actual value) anddefault(default value). This means, by using theextraThe field explanation, you can completely present a rich and diverse content according to the needs of different document models, greatly expanding the expression form of the content.
This design pattern brings great convenience and scalability.It avoids hardcoding all possible fields in the core interface, thus maintaining the simplicity and efficiency of the API.As a user, when you start fromarchive/detailData can be obtained through an interface bymodule_idto determine the model of the current document (such asmodule_id1 usually represents an article, andmodule_idFor 2 may represent a product), and thus can be handled and displayed flexiblyextraField custom data. This enables Anqi CMS to easily handle various content management scenarios from simple blog articles to complex e-commerce products, without the need to design a separate API interface for each content type.
In summary, it is about AnQi CMS'sarchive/detailThe interface design takes into account both generality and specificity. It provides a set of stable basic data structures, and throughprice/stockfields and highly flexibleextraCustom field mechanism, which has realized dynamic adaptation to different types of document data structures. This means that when you are developing, you need to base on themodule_idandextraThe content of the field is analyzed and rendered on the page to make full use of the powerful content management capabilities of Anqi CMS.
Frequently Asked Questions (FAQ)
How can you judge whether a document is an article or a product type?You can use the data returned to find out the following.module_idField to judge the type of document. Anqi CMS assigns uniquemodule_idFor example,module_id1 usually represents the article model, andmodule_idIt may represent a product model. You canmodule/listget detailed information about all modules, including theiridandtitleto establish the corresponding mapping relationship.
2. If I add two custom fields 'Color' and 'Size' to the product model, how will they be reflected in thearchive/detailinterface return data?These custom fields will all be displayed indatathe object'sextrathe field. For example, you might see a structure similar to this:
"extra": {
"color": {
"name": "颜色",
"value": "红色",
"default": ""
},
"size": {
"name": "尺寸",
"value": "XL",
"default": ""
}
}
You need to access their values according to the customfield_name(that is, here in thecolorandsize)
3.dataandextraWhat is the difference between the fields? Do they both contain content?
datafield inarchive/detailThe core data returned by the interface mainly contains the main content of the document, that is,contentfield, is usually the detailed article or product description edited by the rich text editor. andextraThe field is used to store all the fields added to a specific document model through the "Model Management" feature of the AnQi CMS backendCustom fieldIn other words,data.contentis the main content block of the document,extraThe supplementary, structured data surrounding this main content block.