Skip to content
Arun Prakash edited this page Mar 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);

// Typically invoked during app initialization (e.g., on a splash screen)
client.initialize();

πŸ”΅ 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(),
);

client.initialize();

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