wordpress_client 5.3.1
wordpress_client: ^5.3.1 copied to clipboard

A library written purely in dart to interact with Wordpress REST API in a fluent manner. Supports Authorization as well.

WordpressClient

pub.dev

Dart Flutter WordPress

likes popularity pub points

wordpress_client is a library written purely in Dart to interact with Wordpress REST API in a fluent pattern. This library is a port of WordpressCore library written in C# (also written by me)


Features #

  • Complete fluent system, Define request parameters with builder functions which allows to fluently create a request or add extra custom headers, authorization etc.
  • Most common 3 authorization systems are supported.
  • Response preprocessor functions to pre process the response before it gets returned in a ResponseContainer.
  • Provides statistics such as time taken for the request to complete.
  • Support for Custom Requests / Authorization systems.
  • And many more!

NOTE #

Interface API (the way you get posts/users etc) has been changed a lot internally in 5.2.1 (latest) build from previous 5.1.0 build. The new system provides a standard structure for defining custom endpoint requests at the same time keeping request building fluidity. Checkout Custom Requests section for changed API usage.

Usage #

You can use this library just like any other Dart package.

  • Add wordpress_client as a dependency on pubspec.yaml file on your project root. At the time of this writing, the latest package version is 5.1.0. Do check Package Page to get latest version.
dependencies:
  wordpress_client: {latest}
  • Import the library to your project class in which you want to use the library.
import 'package:wordpress_client/wordpress_client.dart';
  • Initializing the client can be done in two ways. It is recommended to initialize WordpressClient once and assign the instance to a variable for later use. Else, if you are using cookies, it may not work properly.

    • Simple method, Initialize with default values.
    • Advanced method (with Bootstrapper to configure various settings like User Agent, Authorization etc)

Simple method #

WordpressClient client = new WordpressClient('https://www.replaceme.com/wp-json', 'wp/v2');

You can read about advanced method in Advanced Method wiki page.

  • Now you are ready to send requests to Wordpress REST API. For example, to send request to get the latest 20 posts in your Wordpress site:
ResponseContainer<List<Post>> response = await client.posts.list(
    (builder) => builder
        .withPerPage(20)
        .withPageNumber(1)
        .sortResultsBy(FilterPostSortOrder.DATE)
        .build(),
  );

Here, the ResponseContainer<T> holds result T object, in this case, its List<Post> as we requested for list of latest posts, with some statistical data, like the time taken for the request to complete (it doesn't count the time taken to process the response information, just the raw request) as a Duration() object.

Supported Authorization methods #

This library has 3 authorization methods currently supported:

For Custom Authorization implementation, Check out Authorization wiki page.

Supported REST Methods #

CreateReadUpdateDelete
Postsyesyesyesyes
Pages------------
Commentsyesyesyesyes
Categoriesyesyesyesyes
Tagsyesyesyesyes
Usersyesyesyesyes
Meyesyesyesyes
Mediayesyesyesyes
Post Revisions------------
Taxonomies------------
Post Types------------
Post Statuses------------
Settings------------

Custom Response Types (Custom Requests) #

Check out Custom Response Types wiki page.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Contributions #

Contributions are always welcome! If you find any bugs/errors, open an issue describing about it and how to reproduce it. :D meanwhile, PR's for new features/bug fixes are always welcome!

License #

MIT

Buy Me A Coffee

2
likes
100
pub points
57%
popularity

A library written purely in dart to interact with Wordpress REST API in a fluent manner. Supports Authorization as well.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

cookie_jar, dio, dio_cache_interceptor, dio_cookie_manager, http_parser, path

More

Packages that depend on wordpress_client