Skip to content

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

License

Notifications You must be signed in to change notification settings

tranvu1805/wordpress_client_extend

This branch is 11 commits ahead of ArunPrakashG/wordpress_client:master.

Repository files navigation

WordPress Client

Pub Version License Stars
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: ArunPrakashG#55

πŸ“¦ Installation

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.

πŸ”§ Usage

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 & Contributing

  • πŸ› For bugs or feature requests, use the issue tracker.
  • πŸ’‘ Contributions are always appreciated. PRs are welcome!

πŸ“„ License

This project is MIT licensed.


If you find this package helpful, consider supporting the development:

Buy Me A Coffee

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 98.9%
  • PHP 1.1%