wordpress_client
Work in progress extension of wordpress_client to implement post meta and custom post types.
π Features
- π‘οΈ 3 Popular authorization methods.
- π£ Events for preprocessing response operations.
- β²οΈ Measures request completion time.
- π¨ Custom Requests & Authorization systems.
- π Request Synchronization.
- β¨ And much more!
π How to Use
1. Setup
Add wordpress_client in your pubspec.yaml:
dependencies:
wordpress_client: ^8.2.1
π‘ Ensure you get the latest version here.
Import the package where you need:
import 'package:wordpress_client_extended/wordpress_client_extended.dart';
2. Initialization
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.
3. Sending Requests
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.
π Supported Authorization
1. AppPasswordAuth
By the WordPress Team, this method uses basic HTTP authentication where credentials are passed with every request. Details
2. BasicJwtAuth
Developed by Enrique Chavez, it involves JSON Web Token (JWT) authentication where a token is issued and then used in subsequent requests. Details
3. UsefulJwtAuth
By Useful Team, this is another implementation using JWT for authentication purposes. Details
For custom authorization, check the Authorization Wiki.
π Supported REST Methods
| Endpoint | Create | Read | Update | Delete |
|---|---|---|---|---|
| Posts | β | β | β | β |
| Comments | β | β | β | β |
| Categories | β | β | β | β |
| Tags | β | β | β | β |
| Users | β | β | β | β |
| Me | β | β | β | β |
| Media | β | β | β | β |
| Pages | β | β | β | β |
| Search | β | β | β | β |
| Post Revisions | β | β | β | β |
| Taxonomies | β | β | β | β |
| Post Types | β | β | β | β |
| Post Statuses | β | β | β | β |
| Settings | β | β | β | β |
π’ Custom Response Types
Learn how to implement Custom Requests here.
π£ Feedback
- π For bugs or feature requests, use the issue tracker.
- π‘ Contributions are always appreciated. PRs are welcome!
π License
Licensed under MIT.
Libraries
- wordpress_client_extended
- A library for interacting with Wordpress REST API with support for Authorization using JWT and Basic Auth.
