Skip to content

Repository files navigation

WordPressPCL

Integration TestsNuGet

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:

.NET implementationVersion support
.NET and .NET Core2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0
.NET Framework4.6.1 2, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Mono5.4, 6.4
Xamarin.iOS10.14, 12.16
Xamarin.Mac3.8, 5.16
Xamarin.Android8.0, 10.0
Universal Windows Platform10.0.16299, TBD
Unity2018.1

Quickstart: Using the API Wrapper

// Client construction//pass the Wordpress REST API base address as stringvarclient=newWordPressClient("http://demo.wp-api.org/wp-json/");//or pass the base address as strongly typed UriconstwpBaseAddress=newUri("http://demo.wp-api.org/wp-json/");varclient=newWordpressClient(wpBaseAddress);//or to reuse an HttpClient pass the HttpClient with base address set to api's base addresshttpClient.BaseAddress=newUri("http://demo.wp-api.org/wp-json/")
var client=newWordpressClient(httpClient);// Postsvarposts=awaitclient.Posts.GetAllAsync();varpostbyid=awaitclient.Posts.GetByIdAsync(id);varpostsCount=awaitclient.Posts.GetCountAsync();// Commentsvarcomments=awaitclient.Comments.GetAllAsync();varcommentbyid=awaitclient.Comments.GetByIdAsync(id);varcommentsbypost=awaitclient.Comments.GetCommentsForPostAsync(postid,true,false);// Pluginsvarplugins=awaitclient.Plugins.GetAllAsync(useAuth:true);varinstalledplugin=awaitclient.Plugins.InstallAsync("akismet");varactivateplugin=awaitclient.Plugins.ActivateAsync(installedplugin);vardeactivateplugin=awaitclient.Plugins.DeactivateAsync(installedplugin);vardeleteplugin=awaitclient.Plugins.DeleteAsync(installedplugin);// Authenticationvarclient=newWordPressClient(ApiCredentials.WordPressUri);//Either Bearer Auth using JWT tokensclient.Auth.UseBearerAuth(JWTPlugin.JWTAuthByEnriqueChavez);awaitclient.Auth.RequestJWTokenAsync("username","password");varisValidToken=awaitclient.IsValidJWTokenAsync();//Or Basic Auth using Application Passwordsclient.Auth.UseBasicAuth("username","password");// now you can send requests that require authenticationvarresponse=client.Posts.DeleteAsync(postId);

Supported REST Methods

CreateReadUpdateDelete
Postsyesyesyesyes
Pagesyesyesyesyes
Commentsyesyesyesyes
Categoriesyesyesyesyes
Tagsyesyesyesyes
Usersyesyesyesyes
Mediayesyesyesyes
Post Revisions---yes---yes
Taxonomies---yes------
Post Types---yes------
Post Statuses---yes------
Settings---yesyes---
Pluginsyesyesyesyes

Additional Features

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.

About

This is a portable library for consuimg the WordPress REST-API in (almost) any C# application

Resources

Code of conduct

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages