Easily interact with the Wordpress REST API. Get support for most common endpoints & CRUD operations.
- ๐ Request Synchronization.
- ๐ฆ API discovery support.
- โฒ๏ธ Measures request completion time.
- ๐ Supports all CRUD operations.
- ๐ Supports all common endpoints.
- ๐จ Custom Requests & Authorization systems.
- ๐ 3 Popular authorization methods.
- ๐ฃ Events for preprocessing response operations.
Add wordpress_client
in your pubspec.yaml
:
dependencies:
wordpress_client: ^8.3.7
๐ก Ensure you get the latest version here.
Import the package where you need:
import 'package:wordpress_client/wordpress_client.dart';
You can initialize WordpressClient
in two methods:
- Default (Simple Method)
- Advanced (with Bootstrapper for additional configurations)
Simple Method:
final baseUrl = Uri.parse('https://example.com/wp-json/wp/v2');
final client = WordpressClient(baseUrl: baseUrl);
client.initialize();
๐ Learn more about the Advanced Method here.
Example to retrieve 20 recent WordPress posts in ascending order:
final request = ListPostRequest(
page: 1,
perPage: 20,
order = Order.asc,
);
final wpResponse = await client.posts.list(request);
// Dart 3 style
switch (wpResponse) {
case WordpressSuccessResponse():
final data = wpResponse.data; // List<Post>
break;
case WordpressFailureResponse():
final error = wpResponse.error; // WordpressError
break;
}
// or
// wordpress_client style
final result = postsResponse.map(
onSuccess: (response) {
print(response.message);
return response.data;
},
onFailure: (response) {
print(response.error.toString());
return <Post>[];
},
);
Refer to the documentation for more request examples.
By the WordPress Team, this method uses basic HTTP authentication where credentials are passed with every request. Details
Developed by Enrique Chavez, it involves JSON Web Token (JWT) authentication where a token is issued and then used in subsequent requests. Details
By Useful Team, this is another implementation using JWT for authentication purposes. Details
For custom authorization, check the Authorization Wiki.
Endpoint | Create | Read | Update | Delete |
---|---|---|---|---|
Posts | โ | โ | โ | โ |
Comments | โ | โ | โ | โ |
Categories | โ | โ | โ | โ |
Tags | โ | โ | โ | โ |
Users | โ | โ | โ | โ |
Me | โ | โ | โ | โ |
Media | โ | โ | โ | โ |
Pages | โ | โ | โ | โ |
Application Passwords | โ | โ | โ | โ |
Search | - | โ | - | - |
Post Revisions | โ | โ | โ | โ |
Taxonomies | โ | โ | โ | โ |
Post Types | โ | โ | โ | โ |
Post Statuses | โ | โ | โ | โ |
Settings | โ | โ | โ | โ |
Learn how to implement Custom Requests here.
- ๐ For bugs or feature requests, use the issue tracker.
- ๐ก Contributions are always appreciated. PRs are welcome!
Licensed under MIT.