View on GitHub

WordPressRestApi

WordPressRestApi : A PCL library to access Wordpress content through the v2 API

WordPressRestApi

WordPressRestApi : A PCL library to access Wordpress content through the v2 API

There are currently two version of this library. PCL and Standard. The .NET Standard version currently supports 1.4.

Donations

This open source project is user supported. Please donate what you can if you find the code useful. Thanks!

Build Status

Build status

Installation

The PCL version - You should probably be using the .NET Standard version below.

Install-Package WmBarrettSimms.WordPressRestApi 

The .NET Standard version

Install-Package WmBarrettSimms.WordPressRestApiStandard 

Supported Platforms

WmBarrettSimms.WordPressRestApi

| .NET Version | Supported | | ———— | ——— | | .NET 4.5 | Yes | | ASP.NET Core 1 | Yes | | Windows 8 | Yes | | Windows Universal 10 | Yes | | Xamarin.Android | Yes | | Xamarin.iOS | Yes | | Xamarin.iOS (Classic) | Yes | | Xamarin.Mac | Yes |

WmBarrettSimms.WordPressRestApiStandard

| .NET Version | Supported | | ———— | ——— | | .NET Standard 1.4 | Yes | | .NET 4.5 | Yes | | ASP.NET Core 1 | Yes | | Windows 8 | Yes | | Windows Universal 10 | Yes | | Xamarin.Android | Yes | | Xamarin.iOS | Yes | | Xamarin.iOS (Classic) | Yes | | Xamarin.Mac | Yes |

Roadmap

I’m prioritizing retreiving data for now. Add, then modify, will come later.

Feature Status Read Add Update Delete
Posts Done Done Done Done Done
Settings Done Done N/A Done N/A
Categories Done Done Done Done Done
Tags Done Done Done Done N/A
Pages Done Done Done Done Done
Media Done Done Done Done Done
Users Partial Done      
Post Types Not planned        
Post Statuses Not planned        
Comments Not planned        
Taxonomies Not planned        

Usage

Creating the client

using WordPressRestApi;
...
WordPressApiClient client = new WordPressApiClient("https://wbsimms.com/wp-json/wp/v2");

Fetching data

Fetch the last 20 posts

List<Post> result = await client.GetPosts(new PostQuery(){PerPage = 20});

Fetch posts with authorId = 1 and catetory = programming

List<Post> result = await client.GetPosts(new PostQuery(){Categories = 531, Author = 1});

Fetch posts with authorId = 1 and tags = 152 and 131

List<Post> result = await client.GetPosts(new PostQuery(){Tags = new List<int>(){152,131}, Author = 1});

Fetch the first 20 non-empty categories

List<Category> result = await client.GetCategories(new CategoriesQuery(){HideEmpty = true, PerPage = 20});

Fetch the first 20 non-empty tags

List<Tag> result = await client.GetTags(new TagsQuery() { PerPage = 20, HideEmpty = true });

Creating data

All create, update, delete operations require authentictaion. Currently, I’m supporting the Application Passwords plugin. You must install this pugin to authenticate. One installed, you need to generate an application password for the API user. All data modification calls require an instance of AuthenticationTokens populated with the WP username and application password. See below for examples.

Create a new Posts

var result = await client.CreatePost(
    new AuthenticationTokens() { ApplicationPassword = "Secret", UserName = "wbsimms" },
    new PostCreate(){Title = "This is a test post",Content = "some content", Excerpt = "unit testing test"});

License