패키지, 저장소 및 앱 카테고리 검색

패키지 상세v10.1.0

wordpress_client

WordPress REST API와 상호 작용할 수 있는 라이브러리입니다. 일반적인 엔드포인트의 대부분과 엔드포인트에서의 모든 CRUD 작업을 지원합니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
1.4천
좋아요
38
Pub 점수
140

패키지 설치

flutter pub add wordpress_client

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Flutter/Dart 패키지로 WordPress REST API와 원활한 상호작용을 가능하게 합니다. 일반적인 엔드포인트와 게시물, 페이지, 댓글 등에 대한 완전한 CRUD 작업을 지원합니다. WordPress 기반 웹사이트와 통합되는 앱을 개발하는 개발자를 위한 것으로, 다양한 플랫폼 간 데이터 검색 및 관리를 단순화합니다. 가볍고 잘 문서화되어 있으며 지속적으로 유지보수되고 있습니다.

사용 사례

  • 블로그 게시물과 페이지를 가져오는 중
  • 프로그래밍을 통해 콘텐츠 생성 및 업데이트
  • 댓글 및 미디어 관리
  • 맞춤형 워드프레스 프론트엔드 빌드
  • WordPress를 헤드리스 CMS로 통합하기

주요 기능

  • 핵심 엔드포인트에 대한 완전한 CRUD 지원
  • 크로스 플랫폼 호환성
  • 간단하고 직관적인 API
  • 토큰을 통한 인증을 지원합니다
  • 내장된 오류 처리 및 응답 파싱

적합한 대상

  • WordPress 통합이 필요한 Flutter 앱
  • 헤드리스 CMS 애플리케이션
  • 콘텐츠 기반 모바일 및 웹 앱
  • 백엔드로 WordPress를 사용하는 개발자

고려 사항

  • 유효한 WordPress REST API 접근 권한이 필요합니다
  • 보호된 엔드포인트에 대한 인증 설정이 필요합니다
  • WordPress REST API 기능에 제한됨
  • 복잡한 워드프레스 전용 논리에 적합하지 않습니다
  • 외부 워드프레스 서버의 안정성에 따라 달라짐

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

WordPress Client

Pub Version License Stars
Dart Flutter WordPress
The modern, strongly‑typed WordPress REST API client for Dart & Flutter — fast, flexible, and production‑ready.

🚀 Features

  • 📦 API discovery support.
  • ⏲️ Measures request completion time.
  • 📝 Supports all CRUD operations.
  • 🌐 Supports all common REST endpoints.
  • 🧩 GraphQL (WPGraphQL) support: client.graphql.query/mutate/raw() with auth.
  • 🎨 Custom Requests & Authorization systems.
  • 🔐 3 Popular authorization methods.
  • 🗄️ Third‑party Database integration.
  • 🔧 Middlewares for request & response operations.
  • 🎣 Events for preprocessing response.
  • 🚀 Execute requests in Parallel (with configurable error handling).
  • 🧠 Optional in‑memory caching for GET requests.
  • 🌊 Polling-based streaming for single-resource retrieve endpoints (works great with Riverpod's StreamProvider).

📦 Install

Add wordpress_client to your pubspec.yaml:

dependencies:
  wordpress_client: ^9.2.0

Then run flutter pub get or dart pub get.

🔧 Quick start

Import and initialize:

import 'package:wordpress_client/wordpress_client.dart';

final client = WordpressClient.forSite(
  siteUrl: Uri.parse('https://example.com'),
  // or: baseUrl via WordpressClient(baseUrl: Uri.parse('.../wp-json/wp/v2'))
);
🧩 GraphQL (WPGraphQL)

If your site uses the WPGraphQL plugin (canonical), you can send GraphQL operations using the same client and auth.

final client = WordpressClient.forSite(
  siteUrl: Uri.parse('https://example.com'),
  bootstrapper: (b) => b
    .withDefaultAuthorization(
      WordpressAuth.appPassword(user: 'user', appPassword: 'xxxx-xxxx'),
    )
    .build(),
);

// Auto-resolves https://example.com/graphql from the REST base.
final result = await client.graphql.query<List<Map<String, dynamic>>>(
  document: '''
    query Posts($limit: Int!) {
      posts(first: $limit) {
        nodes { id title }
      }
    }
  ''',
  variables: { 'limit': 5 },
  parseData: (data) {
    final nodes = (data['posts']?['nodes'] as List<dynamic>? ?? const [])
        .cast<Map<String, dynamic>>();
    return nodes;
  },
  requireAuth: false, // set true for restricted queries/mutations
);

switch (result) {
  case WordpressSuccessResponse():
    print(result.data);
  case WordpressFailureResponse():
    print('GraphQL error: ${result.error}');
}

// Custom endpoint path if your site exposes a different GraphQL path
client.graphql.setEndpointPath('/custom-graphql');

Add an auth quickly (helpers available):

final client = WordpressClient.forSite(
  siteUrl: Uri.parse('https://example.com'),
  bootstrapper: (b) => b
    .withDefaultAuthorization(
      // Built-in helpers
      WordpressAuth.appPassword(user: 'user', appPassword: 'xxxx-xxxx'),
      // or: WordpressAuth.usefulJwt(user: 'user', password: 'pass', device: 'device-id')
      // or: WordpressAuth.basicJwt(user: 'user', password: 'pass')
    )
    .build(),
);

Enable caching via middleware (optional):

final client = WordpressClient(
  baseUrl: Uri.parse('https://example.com/wp-json/wp/v2'),
  bootstrapper: (b) => b
    .withCache(
      ttl: const Duration(minutes: 5),               // optional, default 1 minute
      // cache: MyCustomCacheManager(),              // optional custom store
      // clearOnWrite: false,                        // keep cache after POST/PUT/PATCH/DELETE
    )
    .build(),
);

📝 Notes: applies to GET requests; default store is in-memory (custom stores supported); cache clears by default on writes.

📩 Send a request

Retrieve 20 recent posts in ascending order:

final request = ListPostRequest(
  page: 1,
  perPage: 20,
  order: Order.asc,
);

final response = await client.posts.list(request);

// Dart 3 pattern matching
switch (response) {
  case WordpressSuccessResponse():
    final data = response.data; // List<Post>
    break;
  case WordpressFailureResponse():
    final error = response.error; // WordpressError
    break;
}

// Or use helpers
final posts = (await client.posts.list(ListPostRequest(perPage: 20))).map(
  onSuccess: (s) => s.data,
  onFailure: (f) => <Post>[],
);

final justPosts = (await client.posts.list(ListPostRequest(perPage: 20))).dataOrThrow();

Convenience extensions are available under client.<interface>.extensions for quick lookups and pagination:

final post = await client.posts.extensions.getById(123);
final allMedia = await client.media.extensions.listAll(perPage: 100);

📚 Advanced docs (Wiki)

Deep-dives and more examples live in the Wiki:

🤝 Feedback & Contributing

  • 🐛 For bugs or feature requests, use the issue tracker.
  • 💡 Contributions are always appreciated. PRs are welcome!

Contributor tips (scripts, release process, consistency guards) are documented in the Wiki.

📄 License

This project is MIT licensed.


If you find this package helpful, consider supporting the development:

Buy Me A Coffee

카테고리

의존성

의존성 목록 8 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.