Skip to content
Arun Prakash edited this page May 17, 2024 · 12 revisions

πŸš€ Getting Started

Easily integrate WordPress functionalities into your Dart project with the wordpress_client package.

1. Dependency Installation

Add wordpress_client to your project's pubspec.yaml file:

dependencies:
  wordpress_client: ^{latest}

Make sure to check the Package Page for the most recent version.

2. Library Import

Integrate the library into the desired Dart class:

import 'package:wordpress_client/wordpress_client.dart';

3. Client Initialization

Initialize the WordpressClient using either the simple or advanced method. Ensure to initialize the client once and store its instance for subsequent usage.

🟒 Simple Method

final baseUrl = Uri.parse('https://example.com/wp-json/wp/v2');
final client = WordpressClient(baseUrl: baseUrl);

πŸ”΅ Advanced Method

final baseUrl = Uri.parse('https://example.com/wp-json/wp/v2');
final client = WordpressClient(
    baseUrl: baseUrl,
    bootstrapper: (bootstrapper) => bootstrapper
        .withStatisticDelegate((baseUrl, requestCount) {
          print('$baseUrl -> $requestCount');
        })
        .withDebugMode(true)
        .withDefaultAuthorization(
          UsefulJwtAuth(
            userName: 'username',
            password: 'password',
          ),
        )
        .build(),
);

With custom Dio instance

wordpress_client also offers the flexibility of using a custom Dio instance with the client. This can be achieved by calling WordpressClient.fromDioInstance(...) constructor and by passing the Dio instance via the instance parameter.

That's it! You're now equipped to seamlessly integrate WordPress functionalities into your Dart project using wordpress_client. Happy coding!