- 📦 API discovery support.
- ⏲️ Measures request completion time.
- 📝 Supports all CRUD operations.
- 🌐 Supports all common endpoints.
- 🎨 Custom Requests & Authorization systems.
- 🔐 3 Popular authorization methods.
- 📦 Third party Database integration.
- 🔧 Middlewares for request & response operations.
- 🎣 Events for preprocessing response.
- 🚀 Execute requests in Parallel.
If you find any functionality which you require is missing from the package and you are not able to work it out using built in options like raw requests etc, then please share the functionality in details as a comment here: #55
Add wordpress_client
to your pubspec.yaml
:
dependencies:
wordpress_client: ^8.5.3
💡 Ensure you get the latest version here.
Then run flutter pub get
to install the package.
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);
📘 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 response = await client.posts.list(request);
// Dart 3 style
switch (response) {
case WordpressSuccessResponse():
final data = response.data; // List<Post>
break;
case WordpressFailureResponse():
final error = response.error; // WordpressError
break;
}
// or
// using map method to handle both success and failure
final result = response.map(
onSuccess: (response) {
// response is a WordpressSuccessResponse<List<Post>>
print(response.message);
return response.data;
},
onFailure: (response) {
// response is a WordpressFailureResponse
print(response.error.toString());
return <Post>[];
},
);
// or
// you can cast to a state directly; this will throw an error if the response is of the wrong type
final result = response.asSuccess(); // or response.asFailure();
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!
This project is MIT licensed.