WordPress Client

Pub Version
Dart Flutter WordPress
A powerful and easy-to-use WordPress REST API client for Dart & Flutter.

✨ Features

  • 📦 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.

Future

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: https://github.com/ArunPrakashG/wordpress_client/discussions/55

📖 How to Use

1. Setup

Add wordpress_client in your pubspec.yaml:

dependencies:
 wordpress_client: ^8.4.8

💡 Ensure you get the latest version here.

Import the package where you need:

import 'package:wordpress_client/wordpress_client.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);

📘 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 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.

🔒 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
Application Passwords
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.


Support Me:

Buy Me A Coffee

Libraries

wordpress_client
A library for interacting with Wordpress REST API with support for Authorization using JWT and Basic Auth.