-
Notifications
You must be signed in to change notification settings - Fork 15
Sending Requests
Arun Prakash edited this page Dec 1, 2025
·
5 revisions
Interact with the WordPress REST API by sending requests. For example, to fetch the latest 20 posts in ascending order:
final request = ListPostRequest(
page: 1,
perPage: 20,
order: Order.asc,
);
final wpResponse = await client.posts.list(request);
// Handle response
final result = wpResponse.map(
onSuccess: (response) {
print(response.message);
return response.data;
},
onFailure: (response) {
print(response.error.toString());
return <Post>[];
},
);
// Dart 3 pattern matching
switch (wpResponse) {
case WordpressSuccessResponse():
final posts = wpResponse.data; // typed List<Post>
break;
case WordpressFailureResponse():
final err = wpResponse.error;
break;
}
// Expect success or throw a helpful error
final posts = (await client.posts.list(ListPostRequest(perPage: 10))).dataOrThrow();
// Convenience extension helpers also exist
final one = await client.posts.extensions.getById(123);Utilize the WordpressResponse class to access metadata related to the response, such as request duration and status codes. Differentiate between success and failure responses to handle data appropriately.
- π Welcome to our Wiki!
- π Usage
- π Using Custom Requests
- π‘ Authorization
- π Supported REST Methods
- π API Changelog
- π Middlewares
- π« Parallel Requests
- π§© Interfaces & Extensions
- π‘οΈ Error Handling & Responses
- βοΈ Bootstrap & Configuration
- π Events & Statistics
- π Pagination & Finders