In Anqi CMS, the document URL alias (filenameIt is a very practical feature, which not only makes your website URL more friendly and improves SEO, but also provides great convenience in content acquisition.When you need to obtain detailed information about a specific document through programming, AnQiCMS provides a simple and intuitive API interface.
Core feature revelation: Use document URL alias to get details
To get all the details of the document's URL alias, you will mainly use Anqi CMS'sarchive/detailInterface. This interface is designed to be very flexible, allowing you to accurately retrieve content through the unique ID of the document or its set URL alias.
Imagine that your website has an article about 'AnQi CMS Beginner's Guide', and its URL alias may be set toanqi-cms-guide. When you want to display the full content of this article in a custom page template, mini-program, or any other application, you can directly use this alias for the request without knowing its internal database ID.
How to build a request to get document details
The API address for requesting document details is usually like this:{域名地址}/api/archive/detail. Among them,{域名地址}Replace it with the domain name of your actual website.
The calling method of this interface isGETThis means you can pass request information through URL parameters. There are two core parameters:idandfilenameThey are mutually exclusive, which means you only need to choose one to identify the document you want to retrieve.
You will use for the topic we are discussing today.filenameParameters. For example, if you want to get the URL alias namedanqi-cms-guidedocument, the request URL will be similar to:
https://www.yourdomain.com/api/archive/detail?filename=anqi-cms-guide
After sending such a GET request, AnQi CMS will return all detailed information corresponding to the alias.
Understand the returned data structure deeply
After successfully retrieving the document details, the API will return a JSON-formatted data. This package contains everything you need. Typically, you will see the following key components:
codeandmsgThese two fields are the basis of each API response.code0 indicates that the request was successful,msgThe operation result will be provided in text. If there is an error, it will also give the corresponding error code and reason.dataobject: This is the carrier of all document details. It includes basic properties of the document, such as:id: The unique ID of the document.title: The title of the document.seo_title,keywords,description: This is used for search engine optimization metadata.url_token: This is what we input.filenamethat is the document's URL alias.views,comment_count: Document views and comments.created_time,updated_time: Document's publish and update timestamp.
It is worth mentioning that the actual content and classification information of the document will be in
data.dataanddata.categorythese nested objects.data.data.content: The rich text content of the document, which is usually in HTML format and can be rendered directly on the front-end.data.category: Contains detailed information about the document's category, such as category ID, category name (title), category URL alias (url_token) and so on.data.extra: If your document model has set custom fields, the content of these fields will be presented in thisextraobject in the form of key-value pairs, for example{"author": {"name": "作者", "value": "AnqiCMS"}}This allows your content to have very rich custom attributes.
By parsing these returned data, you can flexibly display document titles, summaries, main content, publication time, and even author information, etc., on the front-end page.
Actual application scenarios and advantages
UsefilenameTo get document details, especially suitable for the following cases:
- Build a front-end page: When you are developing a custom frontend interface, if your routing design is based on URL aliases, then you can directly go through
filenamequeries can simplify the logic of data acquisition. - SEO-friendlyIn front-end frameworks like Vue, React, or mini-programs, when generating SEO-friendly URLs,
filenameCan better correspond to these URLs, maintain consistency of front-end and back-end data requests. - Content migration or synchronization: When importing content or integrating with third-party systems, if the alias is used as a unique identifier, then use
filenameIt can conveniently locate and retrieve specific content.
The advantage of this method lies in the fact that it provides a human-readable, easy-to-manage, and search engine-friendly way to reference and access content on a website, which is more semantically meaningful than simply using a numeric ID.
Summary
Anqi CMS passedarchive/detailthe API and combine withfilenameParameter, it provides you with an efficient, flexible, and easy-to-understand way to obtain document details.In order to optimize SEO, custom development, or content management, mastering this feature will greatly enhance your work efficiency and website user experience.
Frequently Asked Questions (FAQ)
Q: If I have not set a URL alias for the document, can I still use
filenameparameters to get document details?A: No.filenameThe parameter must be passed in the URL alias set in the AnQi CMS background.If the document has not set an alias or you have entered an incorrect alias, the API will not be able to find the corresponding document and will return an error message.In this case, you should use the unique ID of the document (idto get the details.Q:
filenameandidWhich one will be used first when both parameters are passed in?A: Based on the provided document description,idandfilenameIt is an either/or parameter. This means you only need to pass one of them.In most cases, APIs have an internal priority judgment logic, but to ensure the clarity and efficiency of the request, it is recommended that you only pass a valid identifier parameter each time.If you know the document ID clearly, using the ID might be a bit more direct;If you prefer semantically meaningful URLs, then usefilename.Q: Return data in the
extrafield can be used specifically for what?A:extraThe field is a very flexible feature of AnQi CMS, used to store additional field data that you customize for the document model in the background. For example, if you add custom fields such as "author", "source", or "reading time" to the "article" model, the values of these fields will be displayed inextraIt returns. By parsingextraYou can display these rich custom information on the front end, thereby better meeting the diverse content display needs.