WordPressPCL 2.1.0
dotnet add package WordPressPCL --version 2.1.0
NuGet\Install-Package WordPressPCL -Version 2.1.0
<PackageReference Include="WordPressPCL" Version="2.1.0" />
paket add WordPressPCL --version 2.1.0
#r "nuget: WordPressPCL, 2.1.0"
// Install WordPressPCL as a Cake Addin #addin nuget:?package=WordPressPCL&version=2.1.0 // Install WordPressPCL as a Cake Tool #tool nuget:?package=WordPressPCL&version=2.1.0
WordPressPCL
This is a portable library for consuming the WordPress REST-API in (almost) any C# application. If you find bugs or have any suggestions, feel free to create an issue.
Documentation
https://wp-net.github.io/WordPressPCL/
Quickstart
WordPress Requirements
Since WordPress 4.7 the REST API has been integrated into the core so there's no need for any plugins to get basic functionality.
If you want to access protected endpoints, there are two authentication options:
- Authentication using JSON Web Tokens (JWT) (plugin required)
- Basic Authentication using Application Passwords
Supported JWT Authentication Plugins (install either of the following):
To use Application Passwords for authentication read through:
https://make.wordpress.org/core/2020/11/05/application-passwords-integration-guide/
Including WordPressPCL
The WordPressPCL API Wrapper is avaiable through NuGet:
> Install-Package WordPressPCL
Supported Plattforms
WordPressPCL is built on top of the .NET Standard targeting netstandard version 2.0 - therefore it should work on the following plaforms (and newer):
.NET implementation | Version support |
---|---|
.NET and .NET Core | 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0 |
.NET Framework | 4.6.1 2, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8 |
Mono | 5.4, 6.4 |
Xamarin.iOS | 10.14, 12.16 |
Xamarin.Mac | 3.8, 5.16 |
Xamarin.Android | 8.0, 10.0 |
Universal Windows Platform | 10.0.16299, TBD |
Unity | 2018.1 |
Quickstart: Using the API Wrapper
// Client construction
//pass the Wordpress REST API base address as string
var client = new WordPressClient("http://demo.wp-api.org/wp-json/");
//or pass the base address as strongly typed Uri
const wpBaseAddress = new Uri("http://demo.wp-api.org/wp-json/");
var client = new WordPressClient(wpBaseAddress);
//or to reuse an HttpClient pass the HttpClient with base address set to api's base address
httpClient.BaseAddress = new Uri("http://demo.wp-api.org/wp-json/")
var client = new WordPressClient(httpClient);
// Posts
var posts = await client.Posts.GetAllAsync();
var postbyid = await client.Posts.GetByIdAsync(id);
var postsCount = await client.Posts.GetCountAsync();
// Comments
var comments = await client.Comments.GetAllAsync();
var commentbyid = await client.Comments.GetByIdAsync(id);
var commentsbypost = await client.Comments.GetCommentsForPostAsync(postid, true, false);
// Plugins
var plugins = await client.Plugins.GetAllAsync(useAuth:true);
var installedplugin = await client.Plugins.InstallAsync("akismet");
var activateplugin = await client.Plugins.ActivateAsync(installedplugin);
var deactivateplugin = await client.Plugins.DeactivateAsync(installedplugin);
var deleteplugin = await client.Plugins.DeleteAsync(installedplugin);
// Authentication
var client = new WordPressClient(ApiCredentials.WordPressUri);
//Either Bearer Auth using JWT tokens
client.Auth.UseBearerAuth(JWTPlugin.JWTAuthByEnriqueChavez);
await client.Auth.RequestJWTokenAsync("username", "password");
var isValidToken = await client.IsValidJWTokenAsync();
//Or Basic Auth using Application Passwords
client.Auth.UseBasicAuth("username", "password");
// now you can send requests that require authentication
var response = client.Posts.DeleteAsync(postId);
Supported REST Methods
Create | Read | Update | Delete | |
---|---|---|---|---|
Posts | yes | yes | yes | yes |
Pages | yes | yes | yes | yes |
Comments | yes | yes | yes | yes |
Categories | yes | yes | yes | yes |
Tags | yes | yes | yes | yes |
Users | yes | yes | yes | yes |
Media | yes | yes | yes | yes |
Post Revisions | --- | yes | --- | yes |
Taxonomies | --- | yes | --- | --- |
Post Types | --- | yes | --- | --- |
Post Statuses | --- | yes | --- | --- |
Settings | --- | yes | yes | --- |
Plugins | yes | yes | yes | yes |
Additional Features
- Authentication using JSON Web Tokens (JWT)
- HttpResponsePreProcessing: manipulate the API response before deserializing it
Contribution Guidelines
We're very happy to get input from the community on this project! To keep the code clean we ask you to follow a few simple contribution guidelines.
First, create an issue describing what feature you want to add or what problem you're trying to solve, just to make sure no one is already working on that. That also gives us a chance to debate whether a feature is within the scope of this project.
Second, please try to stick to the official C# coding guidelines. https://msdn.microsoft.com/en-us/library/ms229002(v=vs.110).aspx
Also, make sure to write some tests covering your new or modified code.
In order to run the tests on local machine please refer to the install.md file in the dev directory of the repository. Docker along with docker-compose cli will be required to run the tests.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.CSharp (>= 4.7.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on WordPressPCL:
Package | Downloads |
---|---|
BlazingApple.Blog.Services
Package Description |
|
VEFramework.VEDriversLite.Extensions.WooCommerce
.NET drivers for getting information from and to the WooCommerce instance. It can hanlde also communication with main WordPress database |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on WordPressPCL:
Repository | Stars |
---|---|
Webreaper/Damselfly
Damselfly is a server-based Photograph Management app. The goal of Damselfly is to index an extremely large collection of images, and allow easy search and retrieval of those images, using metadata such as the IPTC keyword tags, as well as the folder and file names. Damselfly includes support for object/face detection.
|
Version | Downloads | Last updated |
---|---|---|
2.1.0 | 11,913 | 4/4/2024 |
2.0.2 | 22,344 | 9/25/2023 |
2.0.1 | 54,272 | 12/21/2022 |
2.0.0 | 97,642 | 4/12/2022 |
2.0.0-beta.2 | 222 | 3/22/2022 |
2.0.0-beta | 687 | 3/21/2022 |
2.0.0-alpha | 706 | 1/27/2022 |
1.9.0 | 278,521 | 4/19/2021 |
1.8.5 | 19,660 | 1/6/2021 |
1.8.4 | 1,599 | 12/26/2020 |
1.8.2 | 6,032 | 11/7/2020 |
1.7.2 | 4,848 | 9/22/2020 |
1.7.1 | 84,984 | 5/11/2020 |
1.7.0 | 1,079 | 5/11/2020 |
1.6.2 | 108,858 | 3/19/2019 |
1.6.1 | 9,979 | 11/15/2018 |
1.6.0-beta1 | 1,797 | 11/8/2018 |
1.5.1 | 2,156 | 10/26/2018 |
1.5.0 | 3,951 | 9/10/2018 |
1.4.6 | 1,548 | 8/23/2018 |
1.4.5 | 6,406 | 6/18/2018 |
1.4.4 | 1,713 | 6/2/2018 |
1.4.3 | 1,496 | 6/2/2018 |
1.4.2 | 5,360 | 4/18/2018 |
1.4.1 | 1,509 | 4/18/2018 |
1.4.1-alpha | 1,526 | 3/15/2018 |
1.4.0 | 3,287 | 3/9/2018 |
1.3.3 | 2,318 | 1/29/2018 |
1.3.2 | 1,645 | 1/18/2018 |
1.3.1 | 1,582 | 1/10/2018 |
1.3.0 | 1,980 | 10/30/2017 |
1.3.0-alpha | 1,313 | 10/28/2017 |
1.2.1 | 1,549 | 10/16/2017 |
1.2.0 | 1,571 | 10/7/2017 |
1.1.1 | 1,689 | 9/18/2017 |
1.1.0 | 1,522 | 9/11/2017 |
1.0.0 | 1,801 | 8/9/2017 |
0.1.9 | 1,683 | 6/19/2017 |
0.1.8 | 1,636 | 6/19/2017 |
0.1.7 | 1,598 | 6/1/2017 |
0.1.6 | 1,573 | 5/23/2017 |
0.1.5 | 1,492 | 5/14/2017 |
0.1.4 | 1,610 | 4/30/2017 |
0.1.2-alpha | 1,441 | 3/14/2017 |
0.1.1-alpha | 1,439 | 12/7/2016 |
0.1.0 | 6,571 | 8/18/2016 |
0.0.5 | 1,570 | 8/18/2016 |
0.0.4 | 1,672 | 8/4/2016 |
0.0.3 | 1,625 | 8/4/2016 |
0.0.2 | 1,619 | 8/4/2016 |
0.0.1 | 2,329 | 8/4/2016 |
V2.1.0
- Upgraded dependencies
- Fix GetCurrentUserAsync() naming
- Allow httpclient injection without base address
- Added optional ignoreDefaultPath on CustomRequest methods
V2.0.2
- Support for Plugins
- Support for Statuses in UsersQueryBuilder
- Upgraded Newtonsoft.Json dependency to 13.0.3
V2.0.1
- Upgraded Newtonsoft.Json dependency to 13.0.1
V2.0.0
- Dropped netstandard1.x support
- Added Async-Suffix for all public async methods
- Moved Auth-related functionality to Auth-Sub-Client
- Error handling for WP_DEBUG_DISPLAY
- Moved Settings functionality to Settings-Sub-Client
New Features:
- WordPressClient accepts endpoint also as Uri
- Get total Post count without the actual posts
- Generic JWT and Basic Auth support
V1.9.0
- Support for Application Passwords
- Upped netstandard1.1 to netstandard1.3
V1.8.5
- Bugfix for Query Builder, will now append default enum values to query string for easier debugging
V1.8.4
- Bugfix for HttpClient injection
V1.8.2
- Support for JWT Auth Plugin
V1.7.2
- Added support for posts trash status
- Added support for providing httpclient to WordPressClient
V1.7.1
- Added Icon
- Updated License Expression
V1.7.0
- Added optional MIME-Type override for Media upload
- Improved handling of HttpClient headers
- Downgraded JSON.NET dependency to V11.0.1
- Exceptions Refactoring
V1.6.2
- Clean up file stream after upload #166
- Added .kmz & .kml Mime Types #162
V1.6.1
- Fix for #147 where Capabilities might contain strings instead of bool
V1.6.0-beta1
- marking all Meta properties as dynamic as the structure seems to be very volatile
V1.5.1
- Make height & width optional in MediaSizes (#143)
V1.5.0
- Enhanced Error handling
https://github.com/wp-net/WordPressPCL/issues/138
V1.4.6
- Bugfix: Add DefaultValueHandling to Comment Status property
V1.4.5
- Bugfix: Add NullValueHandling to FeaturedMedia property
V1.4.4
- Add Yoast Taxonomy Terms
V1.4.3
- Bugfix: Add default JsonSerzializerSettings, setting MissingMemberHandling to ignore
V1.4.2
- Bugfix: delete requests return bool instead of HTTPResponseMessage
V1.4.1-alpha
- Experimental WordPress.com support (readonly)
- Experimental Descending Threaded Comments support
V1.4.0
- making HttpClient static
- Exceptions will be thrown instead of hiding them
- don't auto-append /wp-json to WordPress Uri
V1.3.3
- Fixing update of Comment.Status
V1.3.2
- Fixing Comment.Status issue
V1.3.1
- added maxDepth option for threaded comments
V1.3.0
- added ToThreaded-method for transforming comments
- pass deserialization settings into HttpHelper class
- Added .netstandard 2.0 support
- upload media directly from file path (.netstandard 2.0 only)
V1.2.1
- added JWT getter & setter methods
V1.2
- added helper method to sort comments for a threaded view
- added method to get all comments for a post id
- fixed some async issues for better performance
- added logout method