Code Monkey home page Code Monkey logo

wordpress_client's Introduction

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

  • Support for 3 widely used authorization methods.
  • Response preprocessor callback support.
  • Provides statistics such as time taken for the request to complete.
  • Support for Custom Requests / Authorization systems.
  • Request Synchronization using lock objects
  • Nullable support.
  • And many more!

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 6.3.3. Do check Package Page to get latest version.
dependencies:
  wordpress_client: ^6.3.3
  • Import the library to your project class in which you want to use the library. Also, it is to note that imports are split between multiple files, this helps to keep Dart auto-completion less cluttered. i.e., All request classes are seperated into another file, same goes for responses. You can utilize Intellisense to import them easily.
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. State of the properties are stored only in that particular instance of the client.

    • 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 from your Wordpress site in Ascending order, you can use the following code.:
WordpressResponse<List<Post>?> postsResponse = await client.posts.list(
    WordpressRequest(
      requestData: ListPostRequest()
        ..page = 1
        ..perPage = 20
        ..order = Order.asc,
    ),
  );

WordpressResponse is a class which wraps around the actual result object. It also provides access to statistical data related to the response such as the time taken for the request to complete, status codes, Total number of pages etc.

You can access the response object by calling postsResponse.data. It will be null if the request failed or if the library failed to parse the response.

Supported Authorization methods

This library has 3 authorization methods currently supported:

For Custom Authorization implementation, Check out Authorization wiki page.

Supported REST Methods

Create Read Update Delete
Posts yes yes yes yes
Pages --- --- --- ---
Comments yes yes yes yes
Categories yes yes yes yes
Tags yes yes yes yes
Users yes yes yes yes
Me yes yes yes yes
Media yes yes yes yes
Search --- yes --- ---
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

wordpress_client's People

Contributors

arunprakashg avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.