A WordPress API client for dart with support for WooCommerce and custom namespaces.

Overview

WordPress REST API client for Dart | Flutter

All Contributors

GitHub stars Pub Build Status Maintenance

Description

A WordPress REST API client for dart with support for WooCommerce and custom namespaces/endpoints.

Features

  • Retrieve data from standard WordPress endpoints.
  • Retrieve data from any custom namespace

Installation

In the dependencies: section of your pubspec.yaml, add the following line:

dependencies:
  wordpress_api: <latest_version>

Usage

  • Import the package
import 'package:wordpress_api/wordpress_api';
  • Initialize WPAPI
  WordPressAPI api = WordPressAPI('wp-site.com');
  • Retrieve posts from .posts getter

    • You can fetch a list of posts by simply calling .posts. More arguments can be passed to further filter the data returned
      void main() async {
        final api = WordPressAPI('wp-site.com');
        final WPResponse res = await api.posts.fetch();
        for (final post in res.data) {
          print(post.title);
        }
      }
    • As of v0.3.0, you can query a single post from the same endpoint by passing an id

      void main() async {
        final api = WordPressAPI('wp-site.com');
        final WPResponse res = await api.posts.fetch(id: 1);
        print(res.data.title);
      }
    
    
  • Retrieve data from a custom endpoint

  void main() async {
    final api = WordPressAPI('wp-site.com');
    final WPResponse res = await api.get(endpoint: 'your-custom-endpoint');
    print(res.data);
  }

ToDo

  • Authentication using Application Passwords. WordPress 5.6+ only
  • Fully integrated WooCommerce support.
  • Full CRUD operations.
  • Support for other popular WordPress Plugins.

Contributions are welcome, report any issues here

Special Thanks

Contributors ✨

Thanks goes to these wonderful people (emoji key):


anKii

πŸ’»

Kellvem Barbosa

πŸ’»

This project follows the all-contributors specification. Contributions of any kind welcome!

Comments
  • Documentation

    Documentation

    Please provide a full documentation with fully working example to know how to use and fetch posts, pages, categories, tags, images, how to search in posts etc. πŸ‘

    opened by Mayanktaker 4
  • Add more abstraction

    Add more abstraction

    Thanks for the package! I believe you should add more extraction, like a function called getPosts() for fetching posts instead of leaving it up to the dev to read the wp api first. This is how other api clients are written, and it'll also prevent more errors from misspelled endpoints.

    enhancement 
    opened by ThinkDigitalSoftware 4
  • Added the possibility to customize Dio parameters

    Added the possibility to customize Dio parameters

    But once, thanks for this beautiful package, it saves my time and I would like to contribute!

    The possibility of starting Dio with custom parameters is very important, because there are several packages that add incredible functionality to Dio (dio_http_cache) some are listed on the pub.dev/dio page.

    So I added the possibility and I'm requesting this pull...

    This way we can customize the initializer

    final BaseOptions options = BaseOptions(
        connectTimeout: 5000,
        receiveTimeout: 10000,
      );
    
    final wp = WordPressAPI('kellvem.pt', dio: Dio(options));
    

    If you do not want this we can also start in the original way made by you!

    final wp = WordPressAPI('kellvem.pt');
    

    So it's up to the user to use it :))

    opened by kellvembarbosa 3
  • postschema-meta-fixed

    postschema-meta-fixed

    WordPress returns meta field as list [ ] when no meta but, returns map<String, dynamic> when meta fields are available. So I changed the type map<String, dynamic> to dynamic is PostSchema

    opened by 2shrestha22 3
  • Cast Error

    Cast Error

    Using this library with WordPress sites that have meta value in getPosts cause cast error. With the site which have empty meta, meta = [ ] (in JSON ) library is working properly. WordPress API send meta as a map,

    "meta": {
                "spay_email": "",
                "jetpack_publicize_message": ""
            },
    

    in this case library gives type error.

    opened by 2shrestha22 3
  • [fix] change the Utils class to WPUtils to remove error

    [fix] change the Utils class to WPUtils to remove error

    I had an error in the main.dart where there were the Util to call the logger (instant of Logger) based in the lib/src/utils.dart file. I was just about to rename the Utils class to WPUtils which was the actual correct name in the lib/src/utils.dart

    opened by NemesisX1 2
  • Problem with local server

    Problem with local server

    Hello I have installed wordpress on local mamp server. So when i want to fetch post from local server i am getting below errors.

    #0 packages/wordpress_api/src/main.dart 160:18 _discover β”œβ”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„ β”‚ β›” DioError [DioErrorType.response]: XMLHttpRequest error. β”‚ β›” dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 906:28 get current β”‚ β›” packages/dio/src/dio_mixin.dart 819:20 assureDioError β”‚ β›” packages/dio/src/dio_mixin.dart 678:13 _dispatchRequest β”‚ β›” dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 60:31 β”‚ β›” dart-sdk/lib/async/zone.dart 1617:54 runBinary β”‚ β›” dart-sdk/lib/async/future_impl.dart 166:20 handleError β”‚ β›” dart-sdk/lib/async/future_impl.dart 716:46 handleError β”‚ β›” dart-sdk/lib/async/future_impl.dart 737:13 _propagateToListeners β”‚ β›” dart-sdk/lib/async/future_impl.dart 547:5 [_completeError] β”‚ β›” dart-sdk/lib/async/future_impl.dart 603:7 callback β”‚ β›” dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop β”‚ β›” dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop

    opened by kalismeras61 2
  • Exmaple App

    Exmaple App

    We need example app for this library. I am new to programming and having problem with this package.

    Here is code and I don't know data type so put List in return. How should I do if I don't want to put dynamic all over the app code and need a model?

     Future<List<dynamic>> fetchPosts(int pageNum) async {
        return wp.getPosts();
      }
    }
    
    opened by 2shrestha22 2
  • Always 404

    Always 404

    I'm try do work with the sample: import 'package:wordpress_api/wordpress_api.dart';

    WordPressAPI api = WordPressAPI('https://jsonplaceholder.typicode.com/');

    void main() async { final wp = WordPressAPI('https://jsonplaceholder.typicode.com/posts'); final posts = await wp.getPosts(); for (final post in posts) { print(post.title['rendered']); } } But always return 404: Exception: DioError [DioErrorType.RESPONSE]: Http status error [404] #0 WordPressAPI.getAsyc (package:wordpress_api/src/main.dart:249:7) #1 WordPressAPI.getPosts (package:wordpress_api/src/main.dart:281:23) #2 main (package:mercurio_comunicator/getcardContent.dart:7:26) #3 _startIsolate. (dart:isolate-patch/isolate_patch.dart:301:19) #4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

    opened by caam1406 2
  • How to get the typed data when make a request?

    How to get the typed data when make a request?

    currently i am doing this

        final WPResponse response = await api.getPosts();
        final List<PostSchema> posts =
            (response.data as List).map((e) => PostSchema.fromJson(e)).toList();
    

    is there a less boilerplate way and safe?

    thank you

    enhancement 
    opened by CurrySenpai 2
  • Can't get data from WP API if endpoint contains forward slash (/)

    Can't get data from WP API if endpoint contains forward slash (/)

    This code final posts = (await wordpress.getAsync('posts'))['data']; works fine.

    But if you add a forward slash to the endpoint, flutter throws an exception: Invalid argument(s): The source must not be null Sample code: final posts = (await wordpress.getAsync('posts/1'))['data'];

    opened by jkclaudio20 2
  • How to use the search function with this package?

    How to use the search function with this package?

    Hello I'm trying to do a search function for my wordpress posts but I'm not quite sure on how to do with your package, can you refer me to an example made with your package and how it potentially works?

    opened by akotorri 0
  • How to use

    How to use "embedModel"

    Im Sorry for new Topic, but I need help. How can I get url from json below. I use argument const arg = {"per_page": "100", "_embed": "author"}; but I cannot get url. Please help. Thanks

    "_embedded": { "author": [ { "id": 2, "name": "test", "url": "http://egmrm.ru", "description": "", ...

    opened by Willi180 0
  • Where to add Username and Password?

    Where to add Username and Password?

    ToDo Authentication using Application Passwords. WordPress 5.6+ only

    I don't know what does that means. Where should I set my WordPress login info?

    I run the app like example (within localhost WordPress) and I get this error:

    β”‚ #0   packages/wordpress_api/src/main.dart 160:20                          _discover
    β”œβ”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„β”„
    β”‚ β›” DioError [DioErrorType.response]: XMLHttpRequest error.
    
    opened by gabrimatic 2
Releases(v1.2.0)
  • v1.2.0(Sep 22, 2021)

    What's New

    • A new utility abstract class WPUtils has been introduced. This class contains some useful functions.
    • Added EmbedModel thanks Ankii

    What Changed

    • In response to issue #26 , the HTML tags have been preserved. In order to parse the HTML, a utility function from WPUtils is now available as shown in the example below.
        void main() async {
          final api = WordPressAPI('site.com');
          final res = await api.posts.fetch();
    
          for (final post in res.data as List<Post>) {
    
            // This will provide the content as it is without stripping the HTML tags.
            print(post.content);
    
            // This will strip all the HTML tags using parseHtml from WPUtils
            print(WPUtils.parseHtml(post.content));
          }
        }
    
    

    Other contributions

    • Thanks NemesisX1 for prefixing the Utils class
    • Updated Logger to v1.1.0
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(May 2, 2021)

    Breaking Changes

    • Changed the get method on endpoints to fetch. This has been done to preserve the dart keyword get.
    • Changed the return turn for each endpoint to WPResponse. This changed was made to enable more control over the response returned and also get the necessary metadata returned from the response.

    Example 1: Fetch multiple posts

    void main() async {
      final api = WordPressAPI('wp-site.domain');
      final WPResponse res = await api.posts.fetch();
    
       for (final post in res.data) {
        print(post.title);
      }
    }
    

    Example 2: Fetch a single posts

    void main() async {
      final api = WordPressAPI('wp-site.domain');
      final WPResponse res = await api.posts.fetch(id: 26);
    
      final Post post = res.data;
      print(post);
    }
    
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(May 2, 2021)

    Breaking Changes/ What's New

    As of v1+, every api endpoint is set to a getter. For example,

    final WordPressAPI api = WordPressAPI('wp-site.domain');
    
    // Getting posts the OLD WAY
    final List<Post> posts = await api.getPosts();
    
    // The new way as of v1.0+
    final List<Post> posts = await api.posts.get();
    

    The new way is applicable to categories, pages, users, tags, taxonomies, media, application-passwords and any other endpoints to be added.

    Source code(tar.gz)
    Source code(zip)
  • v0.3.0+2(Apr 19, 2021)

  • v0.3.0+1(Apr 19, 2021)

  • v0.3.0(Apr 19, 2021)

  • v0.2.1(Oct 9, 2020)

  • v0.2.0(Jul 22, 2020)

    Breaking Changes

    • Renamed Base*Model to *Schema, e.g BaseCategoryModel is now CategorySchema

    What's New

    • Added Search, Taxonomy, Settings, and Pages endpoints.
    • WPReponse class was added to handle all responses.
    • Additional WordPress schemas that can be extended.
    Source code(tar.gz)
    Source code(zip)
Owner
DHM Group
DHM Group open source projects.
DHM Group
Flutter-for-Wordpress-App - Cross platform wordpress news app built with Flutter and WP REST API

Flutter for Wordpress A flutter app for a wordpress websites with clean and elegant design. This app is available in free and pro version. You can cho

Madhav Poudel 243 Dec 23, 2022
Flutter wordpress - Flutter WordPress API

Flutter Wordpress pub.dev This library uses WordPress REST API V2 to provide a way for your application to interact with your WordPress website. Tutor

Dreamsoft Innovations 183 Nov 17, 2022
Flutter-Wordpress-App - Cross platform wordpress news app built with Flutter

Flutter for Wordpress A flutter app for a wordpress websites with clean and elegant design. This app is available in free and pro version. You can cho

Madhav Poudel 243 Dec 23, 2022
A dart package to interact with the WooCommerce REST API.

WooCommerce SDK for Dart A dart package to interact with the WooCommerce API (now with null-safety). It uses OAuth1.0a behind the scenes to generate t

Samarth Agarwal 87 Dec 28, 2022
Flutter ios/android app to get posts from Wordpress Rest Api

A Wordpress client for Flutter This project uses a simple WordPress website as a backend, without any additional plugin. for more information about Wo

Hooshyar 177 Dec 28, 2022
Woocommerce SDK for Flutter. The Complete Woo Commerce SDK for Flutter.

woocommerce Woocommerce SDK for Flutter. Getting Started Add the package to your pubspec.yaml and import. import 'package:woocommerce/woocommerce.dart

RAY 105 Dec 6, 2022
Flutter custom carousel slider - A carousel slider widget,support custom decoration suitable for news and blog

flutter_custom_carousel_slider A carousel slider Flutter widget, supports custom

Emre 40 Dec 29, 2022
Beautiful Weather App using API with support for dark mode. Created by Jakub SobaΕ„ski ( API ) and Martin GogoΕ‚owicz (UI, API help)

Flutter Weather App using API with darkmode support Flutter 2.8.1 Null Safety Beautiful Weather App using https://github.com/MonsieurZbanowanYY/Weathe

Jakub SobaΕ„ski 5 Nov 29, 2022
Simple app that fetches data from a WordPress blog

Wordpress Blog App A simple Flutter Blog Application, which fetches data from naijatechguy.com, which is a blog, using the blog api. Still working on

Godsend Joseph 26 Nov 23, 2022
Fully Functional IOS/Android App for WordPress Website with Flutter

WordPress App with Flutter IOS/Android Native App for WordPress Website/Blog built using Flutter. No additional Plugins required for WordPress. Built

Atiq Samtia 155 Dec 30, 2022
A wrapper around our Cocoa and Java client library SDKs, providing iOS and Android support for those using Flutter and Dart.

Ably Flutter Plugin A Flutter plugin wrapping the ably-cocoa (iOS) and ably-java (Android) client library SDKs for Ably, the platform that powers sync

Ably Realtime - our client library SDKs and libraries 46 Dec 13, 2022
A Dart EPUB parser built from the ground up, and designed to support a variety of use cases and custom

A Dart EPUB parser built from the ground up, and designed to support a variety of use cases and custom implementations such as on-device caching and serving content from a server.

getBoolean 11 Nov 3, 2022
Dart API Client which wraps the QvaPay API

qvapay_api_client Dart API Client which wraps the QvaPay API The client needs Dio to perform the requests, you must inject an instance in the construc

QvaPay 7 Nov 2, 2022
An Imgur API Client Library that uses Imgur's v3 API for Dart

imgur.dart An Imgur API Client Library that uses Imgur's v3 API for Dart. Usage

null 2 Dec 2, 2022
best flutter / dart practices + Custom Painter + Sliver App Bar + Custom Scrollview

Weekly Budget Flutter App A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get yo

Mohamed Awnallah 4 Oct 21, 2021
Flutter plugin, support android/ios.Support crop, flip, rotate, color martix, mix image, add text. merge multi images.

image_editor The version of readme pub and github may be inconsistent, please refer to github. Use native(objc,kotlin) code to handle image data, it i

FlutterCandies 317 Jan 3, 2023
A customizable carousel slider for Flutter. Supports infinite sliding, custom indicators, and custom animations with many pre-built indicators and animations.

Flutter Carousel Slider A customizable carousel slider for flutter Screenshots Installing dependencies: flutter_carousel_slider: ^1.0.8 Demo Demo a

Udara Wanasinghe 23 Nov 6, 2022
Gaimon - A Flutter plugin to fully support Haptic feedback with custom pattern

Gaimon A Flutter plugin to fully support Haptic feedback with custom pattern. ??

Dimitri Dessus 10 Dec 9, 2022
A customizable carousel slider widget in Flutter which supports inifinte scrolling, auto scrolling, custom child widget, custom animations and built-in indicators.

flutter_carousel_widget A customizable carousel slider widget in Flutter. Features Infinite Scroll Custom Child Widget Auto Play Horizontal and Vertic

NIKHIL RAJPUT 7 Nov 26, 2022