In this post, I will demonstrate how to blog posts from any WordPress website using C#. We will build a Blazor WebAssembly application which will retrieve some posts from a WordPress site and display the posts.

WordPress REST API

The WordPress REST API provides an interface for applications to interact with your WordPress site by sending and receiving data as JSON (JavaScript Object Notation) objects.

An API is an Application Programming Interface. REST, standing for “REpresentational State Transfer,” is a set of concepts for modeling and accessing your application’s data as interrelated objects and collections.

Using the WordPress REST API you can create a plugin to provide an entirely new admin experiences for WordPress, build a brand new interactive front-end experience, or bring your WordPress content into completely separate applications. The WordPress REST API provides REST endpoints (URLs) representing the posts, pages, taxonomies, and other built-in WordPress data types.

Blazor WebAssembly

Blazor is a Microsoft framework for building interactive client-side web UI with .NET. Blazor lets you build interactive web UIs using C# instead of JavaScript. Blazor apps are composed of reusable web UI components implemented using C#, HTML, and CSS. Both client and server code is written in C#, allowing you to share code and libraries.

With Blazor WebAssembly, you can run your client-side C# code directly in the browser. At the same time, you can also use JavaScript with the help of the JavaScript interop. Your C# code can easily call JavaScript APIs and libraries. You can continue to use the large ecosystem of JavaScript libraries that exist for client side UI while writing your logic in C#.

What Will You Need?

I assume that you already have the .Net SDK installed on your PC/Mac. If not, you can download and install the latest version from here. Let’s get right into action.

Step 1: Create a Blazor WebAssembly Project
Step 2: Add the WordPressPCL package from nuget.
Create a form to capture the website URL
Create a grid to display the posts that would be fetched.
Implement the code to fetch from the specified URL.
Run the app and test

We have not implement any validations in the business logic. This demonstration only shows how we can use the WordPress API to fetch posts from a WordPress website with C#.


A reminder that this is only for educational purpose.