How To Extend WP REST API From Your Custom Plugin: Part 4
Tags: blog
Published: 2019-06-17 08:20:08

---
title: How To Extend WP REST API From Your Custom Plugin: Part 4
published: true
tags: Blog
canonical_url: https://upnrunn.com/blog/2018/10/how-to-extend-wp-rest-api-from-your-custom-plugin-part-4/
---

 **This is article 4 of 5 in the series “How To Extend WP REST API From Your Custom Plugin”**. In case you missed the previous tutorials check the list below:

1. 
  1. [How To Extend WP REST API From Your Custom Plugin (Part 1)](https://upnrunn.com/blog/2018/02/extend-wp-rest-api-custom-plugin-part-1/)
  2. [How To Extend WP REST API From Your Custom Plugin (Part 2)](https://upnrunn.com/blog/2018/02/extend-wp-rest-api-custom-plugin-part-2/)
  3. [How To Extend WP REST API From Your Custom Plugin (Part 3)](https://dev.to/kish2011_/how-to-extend-wp-rest-api-from-your-custom-plugin-part-3-4mbk-temp-slug-5990155)

We have created a controller class in the last tutorial to fetch restaurant items and a single restaurant item. A controller class helps to handle the functionality of an endpoint easily. You can learn more about the controller class by reading the REST API Handbook regarding Controller Classes.

In this tutorial, we will write a few controller methods to update or delete a single restaurant item. Make sure you have installed WP Restaurant Listings and the custom plugins we created in the last tutorials.

First, we will add a delete method to the existing route where we can send HTTP request to delete a restaurant item.

<script src="https://gist.github.com/bhoot-biswas/0178803e5da18dd91bb3beac5a9d8431.js"></script>

The delete method we have just added accepts one argument to choose whether to bypass trash and force deletion. However, we have to add two missing methods `delete_item` and `delete_item_permissions_check` also.

<script src="https://gist.github.com/bhoot-biswas/111f0ac0fe1627b2d7c8471925aa7578.js"></script>

Now, our `delete_item` method is ready which is responsible for deleting a restaurant item. We will write logic in `delete_item_permissions_check` method to check if a given request has access to delete a restaurant item.

<script src="https://gist.github.com/bhoot-biswas/41cf6d2e22c2a41f4af038c601a2e3c2.js"></script>

You have noticed that we are using the `get_restaurant` method, let us add this method also.

<script src="https://gist.github.com/bhoot-biswas/234f3ec538948e7934ba277ac92b78ca.js"></script>

Finally, everything is ready to delete a restaurant item by sending a simple HTTP `DELETE` request.

Let’s send a HTTP `DELETE` request to `wp-json/rest-tutorial/v1/restaurants/{id}` endpoint. If the restaurant has been deleted successfully you will get the following response.

<script src="https://gist.github.com/bhoot-biswas/372110ce72b837daa9e9ad6bddf566b6.js"></script>

When sending a request using [Postman](https://www.getpostman.com/) make sure you have installed [Basic Auth](https://github.com/WP-API/Basic-Auth) plugin for basic authentication.

You also can set param `force=true` to permanently delete item instead of moving to trash.

In the next tutorials, we will learn how to create and update a restaurant item by sending the HTTP POST method.

The post [How To Extend WP REST API From Your Custom Plugin: Part 4](https://upnrunn.com/blog/2018/10/how-to-extend-wp-rest-api-from-your-custom-plugin-part-4/) appeared first on [upnrunn® | Build & Deploy Powerful Application](https://upnrunn.com).