Drupal/C4/RESTful-API-with-a-REST-Client/English-timed

From Script | Spoken-Tutorial
Jump to: navigation, search
Time
Narration
00:01 Welcome to the spoken tutorial on RESTful API with a REST Client.
00:06 In this tutorial, we will learn about REST client.
00:11 We also learn to use the REST client to Retrieve data using GET method
00:17 Create a new node using POST method
00:20 Modify an existing node using PATCH method and
00:24 Delete an existing node using DELETE method
00:28 To record this tutorial, I am using Ubuntu Linux 16.04
00:34 Drupal 8
00:36 Postman as a REST client and Firefox web browser
00:41 You can use any REST client and web browser as per your choice.
00:46 To practise this tutorial, you should have basic knowledge of Drupal.
00:52 The RESTful API should have been implemented in your Drupal website.
00:57 If not, please go through the previous Drupal tutorials on this website.
01:03 You should also have a working Internet connection.
01:08 First we will confirm whether RESTful API is implemented in our Drupal8 site.

To do so, open our Drupa8 site.

01:18 Then go to Structure and Views.
01:23 Here you can see that RESTful API is implemented in the Events content type.
01:30 Note that we have already learnt to implement the RESTful API earlier.
01:35 Now we will learnt to check our RESTful API using a REST client.
01:41 I will use Postman as a REST client.
01:44 You can use any REST client as per your choice.
01:49 Postman is a powerful HTTP client for testing web services.
01:54 To install the Postman client, refer to the Additional reading material link of this tutorial.
02:01 The following steps are applicable to Bitnami Drupal Stack.
02:06 But most of the steps are applicable to any other Drupal installation, as well.
02:12 Let us open the Postman client.
02:15 First we will learn to retrieve data for Anonymous users using GET method.
02:21 Choose GET from the drop-down list.
02:24 Recall that earlier we had implemented the RESTful API on our Events content type.
02:31 We will now enter the path of our RESTful API.
02:36 Here localhost:8080 is my server name.
02:41 If you are not using Bitnami Drupal stack, please use localhost instead of localhost:8080.
02:50 drupal is the folder of my Drupal instance.
02:53 events is the content type on which we have configured the RESTful API.
03:00 Now click on the Send button at the top right corner.
03:03 You can see here the contents of our events content type in json format.
03:09 Next let us learn to retrieve a single node.
03:13 Click on the plus button at the top panel to add a new tab.
03:18 Choose GET from the dropdown list.
03:21 We have to give the exact path of the particular node.
03:25 Click on the Send button. You can see here the content of that particular node is retrieved.
03:32 Next let us learn to create a new node for Authenticated users using POST method.
03:39 Click on the plus button at the top panel to add a new tab.
03:44 Choose POST from the drop-down list.
03:47 Type the path as shown. Here localhost:8080 is my server name.
03:55 drupal is the folder of my Drupal instance.
03:59 We have to hard-code the rest of the things.
04:02 Under Authorization, we will change the Type as Basic Authentication.
04:08 Now we will give the username and password of our Drupal website.
04:13 Click on the Preview Request button at the left hand side to update our request.
04:19 Click on the Headers tab. Here you can see the token for the basic authentication.
04:26 We will set the Content-Type to application/hal+json.
04:32 Now we will go to the Body tab.
04:34 Let us change the data format as raw.
04:38 Here we must declare the required title and type fields.
04:43 So type the following code.
04:46 This json code is used to create a new code of the type events.
04:52 For that we specify the values for title and body fields.
04:57 The same code is given in the Code files link of this tutorial.
05:02 Please download and use it.
05:05 Click on the Send button at the top right corner.
05:09 If the content is successfully posted, you can see the json code of this content at the bottom.
05:16 We can also check the content in our Drupal website.
05:20 Switch back to our Drupal site.
05:23 Here you can see the event which is posted from the Postman client.
05:28 Note that the UID of this post is 100.
05:32 We will use this UID in the postman client to modify this node.
05:38 Next let us learn to modify a node for Authenticated users using PATCH method.
05:45 Let us switch back to the Postman client.
05:48 Click on the plus button at the top panel to add a new tab.
05:52 Choose PATCH from the drop-down list.
05:55 We will enter the URL of the node which we want to modify.
06:00 For example, we will modify the node which we created using POST method.
06:05 The UID of this post is 100. We will enter the URL of the node 100.
06:14 Under Authorization, we will change the Type as Basic Authentication.
06:20 Now we will give the username and password of our Drupal website.
06:25 Click on the Preview Request button at the left hand side.
06:28 Click on the Headers tab. Here you can see the token for the basic authentication.
06:35 We will set the Content-Type to application/hal+json.
06:41 Now we will go to the Body tab.
06:44 Change the data format as raw.
06:47 And type the following code here.
06:51 In this code we modify the values for both the title and the body fields.
06:57 The same code is given in the Code files link of this tutorial.

Please download and use it.

07:05 Then click on the Send button at the top right corner.
07:09 You can see the Status as 200 OK which means the content is modified.
07:16 Let us check the content in our Drupal website.
07:20 Switch back to our Drupal website. Let us refresh the page.
07:25 Here you can see that the event is successfully modified using the PATCH method.
07:31 Next let us learn to delete an existing node for Authenticated users using DELETE method.
07:38 I will choose node 100 which was created by me as an authenticated user.
07:44 Remember that we have permitted the authenticated users to delete their own content only.
07:50 Switch back to the Postman client. Click on the plus button to add a new tab.
07:57 Choose DELETE from the drop-down list.
08:00 We will enter the URL of the node which we want to delete.
08:04 Under Authorization, we will change the Type as Basic Authentication.
08:10 Now we will give the username and password of our Drupal website.
08:14 Click on the Preview Request button at the left hand side.
08:18 Then click on the Headers tab.
08:21 We will set the Content-Type to application/hal+json.
08:28 Click on the Send button at the top right corner.
08:31 You can see the Status as 204 No content which means the content is deleted.
08:38 Switch back to our Drupal site.
08:41 Let us refresh the page.
08:43 We can see that the node is successfully deleted.
08:47 This is all about managing content through Postman client.

With this, we come to the end of this tutorial.

08:55 Let us summarize. In this tutorial, we have learnt about- Postman client as a REST client and
09:03 Managing content through Postman client using GET, POST, PATCH and DELETE methods
09:10 As an assignment - Create some new articles through REST client and Modify the articles using PATCH method
09:19 The video at the following link summarises the Spoken Tutorial project. Please download and watch it.
09:27 The Spoken Tutorial Project Team conducts workshops and gives certificates to those who pass online tests.

For more details, please write to us.

09:38 Spoken Tutorial Project is funded by NMEICT, Ministry of Human Resource Development and NVLI, Ministry of Culture

Government of India.

09:49 This tutorial is contributed by Vishal Jindal.

This is Priya from IIT Bombay signing off. Thanks for joining.

Contributors and Content Editors

PoojaMoolya