This is our third part of Angular universal, In this tutorial, we see how to create a rest API in WordPress and JSON formatted chrome extension.

Rest API in WordPress

Rest API is a URL to communicate between client and server via that URL. WordPress has an inbuilt rest is there. In this section, we need to customize the API for adding the category section.

By default, WordPress doesn’t have the category section in the WordPress post API.So we need to add some function to add the category section in the WordPress theme file. Before working on the theme file, you need to take a backup for editing.

I write a function here for getting the category details for posts.

function rest_api($data,$post,$request){ //Data
	$_data = $data->data;

	//Get the category using Post ID
	$category = get_the_category($post->ID);
	$_data['category']=$category;
	$data->data = $_data;

	return $data;

}

add_filter('rest_prepare_post','rest_api',10,3);

File Link

Click here to view function.php

Explanation and Demo video for the code Video Link

JSON Formatter 

In chrome when seeing JSON format not able to view the good appearance, it seems cumbersome. This JSON formatted chrome extension will help to see some clear view for that.

  Json Formatter

Git Hub Repository Link  for Frontend and Backend Universal

  Github Repo Frontend Gitub Repo Backend