Wordpress Plugin - Expose REST API - wordpress

I'm trying to write a plugin that would add these endpoints GET, POST, DELETE /api/checked to access the plugin's custom table.
Is it possible for a Wordpress plugin to expose a RESTful API? I can't seem to find any examples or documentation.
The closest thing I found was add_rewrite_rule. I was able to create http://www.blog.com/api, but how do I determine the HTTP verb?

You can use WP REST API. Just install it and then go to settings -> permalink and add /%postname%/ on the last field.
then you'll have everything you need at [url]/json-api/
Here is the doc

You can use JSON-API WordPress plugin for creating the web-services that can be used for fetching the data from Wordpress.
And the plugin will provide the webservice url something like that :
www.mysite.com/api/servicename
Plugin link : https://wordpress.org/plugins/json-api/
Hope it helps you some extent.

Related

Can I get Wordpress Plugin Data through Wordpress API?

I am looking to build a wordpress website with GatsbyJS (so no PHP usage. Just using Wordpress API and react JSX on the front-end).
I know I can get any core wordpress data at /wp-json route, but I'm not sure about plugin data. I've tried to look up plugin data and it does not seem to be included in wp-json.
I found this "compatible plugins" page: https://v2.wp-api.org/guide/plugins/
Does this mean that for most other plugins data would not be present in the Wordpress API?
Correct. Unless these plugins expose their data via the REST API (either by extending the existing endpoints or by creating their own, like some plugins do), you won't be able to access it.
In such cases, you either ask the developers to expose their plugin's data via the REST API or you code some custom endpoints yourself to get the data you need from them.

Wordpress API without installation

I am trying to use the wordpress API to retrieve recent blog posts from a wordpress blog, and display them on a non-wordpress site.
I have read a bunch of tutorials and the documentation on implementing the API, all of which state that you must install wordpress on your server in order to use the API.
Is this definitely the only use case? Is there an implementation I can use which does not require us to install wordpress on the server?
All I want to do is retrieve recent posts and display them in a list which will link out to the actual wordpress blog.
The folks commenting are confused by your statement, because they all assume (as highly technical individuals do), you're referring to a self-hosted WordPress.
No. You do NOT have to have a WordPress install to use the WordPress**.COM** API.
Example:
https://public-api.wordpress.com/wp/v2
Documentation:
https://developer.wordpress.com/docs/api/
Good luck!

Create a blog through the Rest API

I need to migrate content from Ning to WordPress 4.1 and I'm planning to use Rest Api(json-api plugin) for that purpose. But i get confused a little bit, there is no methods for creating blogs, events etc.
Is it possible to create blog using Rest Api?
You can use JSON-API WordPress plugin for creating the restful web-services that can be used for fetching the data from Wordpress.
And the plugin will provide the webservice url something like that :
www.mysite.com/api/servicename
Plugin link : https://wordpress.org/plugins/json-api/
Hope it helps you some extent.

Wordpress custom url from plugin

I want to be able to create url from plugin. for example. A new url would be http://example.com/slug-set-from-plugin which will output contents from plugin methods. Is it doable?
Use the Rewrite API, in your case: add_rewrite_endpoint(). See this example for detailed instructions.

wordpress restrict pulgin installation to those who have a unique code

i want to make an wordpress plugin, and to put it public, but i want that only the users that have a certain unique code to be able to activate it.
is there possible using the wordpress api to ask for a unique code at plugin activation (and to condition the plugin activation by this code)? I searched wordpress codex, but nothing found.
thanks a lot!
This sounds like the old akismet plugin which required users to register for an API token. You can as part of your plugin require users to enter settings and at this point prompt them to register for an API key.
See the WordPress codex for adding an options page.
Also see this example for a good example of hooking into the plugin activation:

Resources