Home >CMS Tutorial >WordPress >About the basic use of WordPress REST API

About the basic use of WordPress REST API

藏色散人
藏色散人forward
2020-05-17 14:28:353861browse

The following column WordPress Website Building Tutorial will introduce you to the basic use of WordPress REST API. I hope it will be helpful to friends in need!

About the basic use of WordPress REST API

The WordPress system opens REST API by default, that is to say, in addition to outputting content in HTML format,

can also output content in JSON format Output article/user/comments and other data.

The reason why JSON data format response is supported is because currently various smart terminal devices, such as mobile phones/tablets/TVs/routers/home appliances/toys, etc.,

have to communicate with the cloud server. Communication, and the data required by the terminal device does not necessarily have to be presented to the user after parsing HTML by the browser.

So JSON, a data format specification that is easy to write/read/parse, is usually used for data communication.

If you have deployed WordPress, you can get data in JSON format through the corresponding link:

Link format example:

Article list9e6c6f86673efa96e9f4645ec38e5f75/wp- json/wp/v2/posts

Page list9e6c6f86673efa96e9f4645ec38e5f75/wp-json/wp/v2/pages

User list9e6c6f86673efa96e9f4645ec38e5f75/wp-json/wp/v2/ users

Replace the example domain name with your own domain name. If the page returns a 404 error, you need to set the redirection rules of the WEB proxy server (Nginx).

For the complete resource API link, please visit

https://developer.wordpress.org/rest-api/reference/

It can be seen that if the website wants to provide data interface services for other devices, it can be used directly without development costs.

If you do not want your website to open the REST API, you can disable this feature by installing the plug-in Disable REST API.

Plug-in address:

https://wordpress.org/plugins/disable-json-api/

After installation and activation, except for the logged-in administrator, other users have no permission to access data.

In order to make JSON data easy to read in the browser, you can install related extensions:

Chrome :

https://chrome.google.com/webstore/detail/json-viewer/aimiinbnnkboelefkjlenlgimcabobli?utm_source=chrome-ntp-icon

For more WordPress technical articles, please visit WordPress TipsColumn!

The above is the detailed content of About the basic use of WordPress REST API. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete