Drupal/C4/RESTful-API-Implementation/English-timed
From Script | Spoken-Tutorial
Revision as of 16:53, 25 June 2018 by PoojaMoolya (Talk | contribs)
|
|
00:01 | Welcome to the spoken tutorial on RESTful API Implementation. |
00:06 | In this tutorial, we will Understand what is RESTful API |
00:11 | Learn to implement RESTful API using Views |
00:16 | To record this tutorial, I am using Ubuntu Linux 16.04 |
00:22 | Drupal 8 and Firefox web browser |
00:25 | You can use any web browser as per your choice. |
00:29 | To practise this tutorial, you should have basic knowledge of Drupal. |
00:34 | If not, for relevant Drupal tutorials, please visit the link shown. |
00:40 | You should also have a working Internet connection. |
00:44 | What is RESTful API? |
00:47 | RESTful API is based on REpresentational State Transfer (i.e REST) technology. |
00:55 | It is also referred to as a RESTful web service. |
01:00 | RESTful API provides methods to external clients to fetch, add or modify data on the server. |
01:08 | For example: Using the same server, we can do a bank transaction either using a mobile app or desktop website. |
01:17 | RESTful API is a general purpose API. |
01:20 | So any application, such as another website, native mobile apps and IoT devices can exchange data with your server. |
01:31 | Let us learn the RESTful API implementation process step by step. |
01:37 | The following steps are applicable to Bitnami Drupal Stack. |
01:41 | But most of the steps are applicable to any other Drupal installation, as well. |
01:47 | Step No. 1
First we will open our Drupal8 site and install the required core modules. |
01:55 | To do so, go to the Extend tab. |
01:59 | Scroll down and go to the WEB SERVICES section. |
02:03 | Put a check mark on the following modules: HAL, HTTP Basic Authentication, RESTful Web Services and Serialization. |
02:15 | Then click on the Install button at the bottom, to enable them. |
02:20 | We will also need to install the REST UI module manually. |
02:25 | I have already installed and enabled it in my machine. |
02:29 | To know how to install a module, go through the Creating Dummy Content tutorial in this series. |
02:37 | Step No. 2
Next we will configure the REST resources to accept the requests from a REST client. |
02:45 | To do so, go to the Configuration tab. Click on REST under WEB SERVICES. |
02:52 | The REST resources page appears now. |
02:55 | We will restrict the formats by clicking on the Edit button of Content. |
03:01 | Scroll down. Under Accepted request formats, put a check mark on the json. |
03:08 | Click on the Save configuration button at the bottom to save it. |
03:13 | Now our Drupal site will accept the json format requests from a REST client. |
03:19 | Step No. 3
Next we need to set the proper permissions for authenticated users. |
03:26 | In general, there are three kind of users that can use RESTful API. |
03:32 | anonymous user |
03:34 | authenticated user and |
03:36 | authenticated users with permission to modify content |
03:41 | Now, we will setup our Drupal for an authenticated user who can create, edit, and delete their own contents. |
03:50 | To do so, go to People tab. |
03:53 | Click on the Permissions tab. |
03:57 | Scroll down and for AUTHENTICATED USER, put a checkmark on Basic Page: Create new content |
04:04 | Basic Page: Delete own content |
04:07 | Basic Page: Edit own content |
04:10 | Click on the Save permissions button at the bottom. |
04:13 | I have enabled the authenticated users to create, edit and delete their own content. |
04:20 | You can give permissions based on your requirements. |
04:24 | Step No. 4
Now we need a content type on which we want to implement the RESTful API. |
04:32 | Go to Structure tab and click on the Content types. |
04:37 | I will use the Events content type to implement the RESTful API. |
04:42 | You can use any content type as per your requirement. |
04:47 | Step No. 5
Now we need a View for our Events content type. |
04:53 | To know about Views, go through the tutorial Displaying Contents using Views of this series. |
05:00 | To create a new view, go to Structure and Views. |
05:06 | Click Add view and let’s name it as Events underscore view. |
05:12 | Change the content of type from All to Events. |
05:17 | Under REST EXPORT SETTINGS, check Provide a REST export. |
05:22 | We will type the REST export path as events. |
05:27 | Click Save and edit button at the bottom. |
05:30 | Now we will set up the display of our events. |
05:34 | Under FORMAT section, in the Show option, click on the Entity. |
05:39 | In the REST export dialog box that appears, choose Fields option. |
05:45 | Click on the Apply button. |
05:47 | In the Row style options dialog box, keep the settings as it is. |
05:53 | Then click on the Apply button. |
05:55 | This will enable us to add fields to our view. |
06:00 | Now we can add all the fields of our Events content type. |
06:04 | Click on the Add button. |
06:06 | This brings up the list of available fields. |
06:10 | In the Search box, type body. |
06:13 | Choose Body from the list, then click on the Add and configure fields button. |
06:20 | Click on the Apply button. |
06:22 | Again click on the Add button to add another field. |
06:27 | Search for id and choose ID from the list. |
06:32 | Click on the Add and configure fields button. |
06:36 | Then click on the Apply button. |
06:38 | Under PATH SETTINGS, we can see the path of our events view. |
06:43 | We will click on the Save button to save this view. |
06:47 | Step No. 6
Next we will create a new view to retrieve the data. |
06:54 | Click on the Add button in the Displays panel. |
06:59 | Select REST export option. |
07:02 | Now let us configure this new view. |
07:05 | Under FORMAT section, click on the Entity. |
07:09 | Choose Fields option and click on the Apply button. |
07:14 | Check all the fields that we want in our content type.
And click on the Apply button. |
07:20 | Here you can see that our required fields are added now. |
07:25 | Under PATH SETTINGS, we will set the path by clicking on the No path is set link. |
07:31 | In the Path field, type events slash percentage sign. |
07:37 | Percentage sign is used to represent values that will be used for the contextual filter. |
07:44 | Click on the Apply button at the bottom. |
07:47 | Now, in the right hand side, click on the ADVANCED option. |
07:51 | Under CONTEXTUAL FILTERS, click on the Add button. |
07:56 | We will add an ID for the contextual filter to refer our node. |
08:00 | Search for id and choose the ID from the list. |
08:05 | Click on the Apply button. |
08:07 | Keep the other settings as it is. |
08:10 | Then click on the Apply button. |
08:13 | Click on the Save button to save this configuration. |
08:17 | With this, we have successfully implemented the RESTful API in our Drupal site using Views. |
08:24 | Later in the series, we will learn how to check our RESTful API using a REST Client. |
08:31 | With this, we come to the end of this tutorial. |
08:34 | Let us summarize. |
08:36 | In this tutorial, we have learnt about- RESTful API and Implementation of RESTful API using Views |
08:45 | As an assignment - Implement the RESTful API on the Article content type |
08:51 | The video at the following link summarises the Spoken Tutorial project.
Please download and watch it. |
08:58 | The Spoken Tutorial Project Team conducts workshops and gives certificates to those who pass online tests.
For more details, please write to us. |
09:09 | Spoken Tutorial Project is funded by NMEICT, Ministry of Human Resource Development and NVLI, Ministry of Culture Government of India. |
09:19 | This tutorial is contributed by Vishal Jindal.
This is Priya from IIT Bombay signing off. Thanks for joining. |