A WordPress REST API client for dart with support for WooCommerce and custom namespaces/endpoints.
Features
Retrieve data from standard WordPress endpoints.
Retrieve data from any custom namespace
Installation
In the dependencies: section of your pubspec.yaml, add the following line:
dependencies:wordpress_api:<latest_version>
Usage
Import the package
import'package:wordpress_api/wordpress_api';
Initialize WPAPI
WordPressAPI api = WordPressAPI('wp-site.com');
Retrieve posts from .posts getter
You can fetch a list of posts by simply calling .posts. More arguments can be passed to further filter the data returned
voidmain() async {
final api = WordPressAPI('wp-site.com');
finalWPResponse res = await api.posts.fetch();
for (final post in res.data) {
print(post.title);
}
}
As of v0.3.0, you can query a single post from the same endpoint by passing an id
voidmain() async {
final api = WordPressAPI('wp-site.com');
finalWPResponse res = await api.posts.fetch(id: 1);
print(res.data.title);
}
Retrieve data from a custom endpoint
voidmain() async {
final api = WordPressAPI('wp-site.com');
finalWPResponse res = await api.get(endpoint: 'your-custom-endpoint');
print(res.data);
}
ToDo
Authentication using Application Passwords. WordPress 5.6+ only