Difference between revisions of "Drupal/C4/RESTful-API-Implementation/English"
(Created page with " {| style="border-spacing:0;" | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| <cent...") |
|||
(One intermediate revision by one other user not shown) | |||
Line 15: | Line 15: | ||
* Understand what is '''RESTful API''' | * Understand what is '''RESTful API''' | ||
* Learn to implement '''RESTful API '''using '''Views''' | * Learn to implement '''RESTful API '''using '''Views''' | ||
− | |||
− | |||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| In this tutorial, we will | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| In this tutorial, we will | ||
* Understand what is '''RESTful API''' | * Understand what is '''RESTful API''' | ||
* Learn to implement '''RESTful API '''using '''Views''' | * Learn to implement '''RESTful API '''using '''Views''' | ||
− | |||
− | |||
|- | |- | ||
Line 34: | Line 30: | ||
* Drupal 8 | * Drupal 8 | ||
* Firefox web browser | * Firefox web browser | ||
− | |||
− | |||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| To record this tutorial, I am using | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| To record this tutorial, I am using | ||
Line 68: | Line 62: | ||
* It is based on '''RE'''presentational '''S'''tate '''T'''ransfer ('''REST''') technology | * It is based on '''RE'''presentational '''S'''tate '''T'''ransfer ('''REST''') technology | ||
− | * It is also referred to as a RESTful web service | + | * It is also referred to as a '''RESTful web service''' |
Line 74: | Line 68: | ||
* '''RESTful API '''is based on''' REpresentational State Transfer (i.e REST) '''technology. | * '''RESTful API '''is based on''' REpresentational State Transfer (i.e REST) '''technology. | ||
− | * It is also referred to as a RESTful web service. | + | * It is also referred to as a '''RESTful web service'''. |
− | * '''RESTful API''' provides methods to external clients to fetch, add or modify data on the server. | + | * '''RESTful API''' provides methods to external '''clients''' to fetch, add or modify data on the '''server'''. |
− | + | ||
− | + | ||
|- | |- | ||
Line 83: | Line 75: | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| For example: | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| For example: | ||
− | * Using the same server, we can do a bank transaction either using a mobile app or desktop website. | + | * Using the same '''server''', we can do a bank transaction either using a mobile app or desktop website. |
− | + | ||
− | + | ||
|- | |- | ||
Line 92: | Line 82: | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| RESTful API is a general purpose API. | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| '''RESTful API''' is a general purpose '''API'''. |
So any application, such as | So any application, such as | ||
− | |||
* another website, | * another website, | ||
− | * native mobile apps and | + | * native '''mobile apps''' and |
− | * IoT devices | + | * '''IoT devices''' |
− | can exchange data with your server. | + | can exchange data with your '''server'''. |
|- | |- | ||
Line 135: | Line 124: | ||
|- | |- | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| Put a check mark on '''HAL, HTTP Basic Authentication, RESTful Web Services ''' | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| Put a check mark on '''HAL, HTTP Basic Authentication, RESTful Web Services ''' |
− | + | ||
+ | and''' Serialization''' | ||
+ | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| Put a check mark on the following modules: | ||
'''HAL, HTTP Basic Authentication, RESTful Web Services '''and''' Serialization.''' | '''HAL, HTTP Basic Authentication, RESTful Web Services '''and''' Serialization.''' | ||
Line 213: | Line 203: | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| In general, there are three kind of users that can use '''RESTful API'''. | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| In general, there are three kind of '''users''' that can use '''RESTful API'''. |
+ | 1. '''anonymous user''' | ||
− | + | 2. '''authenticated user''' and | |
− | + | 3. '''authenticated users''' with permission to modify content | |
− | |||
− | + | Now, we will setup our '''Drupal''' for an '''authenticated user''' who can create, edit, and delete their own contents. | |
− | Now, we will setup our '''Drupal''' for an authenticated user who can create, edit, and delete their own contents. | + | |
|- | |- | ||
Line 242: | Line 231: | ||
* Basic Page: Delete own content | * Basic Page: Delete own content | ||
* Basic Page: Edit own content | * Basic Page: Edit own content | ||
− | |||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| Scroll down and for '''AUTHENTICATED USER''', put a checkmark on | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| Scroll down and for '''AUTHENTICATED USER''', put a checkmark on | ||
Line 252: | Line 240: | ||
Click on the '''Save permissions''' button at the bottom. | Click on the '''Save permissions''' button at the bottom. | ||
− | + | |- | |
− | I have enabled the '''authenticated users''' to create, edit and delete their own content. | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| |
+ | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| I have enabled the '''authenticated users''' to create, edit and delete their own content. | ||
Line 397: | Line 386: | ||
− | We will click on the '''Save''' button | + | We will click on the '''Save''' button to save this '''view'''. |
Line 446: | Line 435: | ||
|- | |- | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| Click''' No path is set''' | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| Click''' No path is set''' | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| Under '''PATH SETTINGS''', we will set the path by clicking on the '''No path is set''' | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| Under '''PATH SETTINGS''', we will set the path by clicking on the '''No path is set''' link. |
|- | |- | ||
Line 520: | Line 509: | ||
In this tutorial, we have learnt about- | In this tutorial, we have learnt about- | ||
− | |||
* '''RESTful API '''and | * '''RESTful API '''and | ||
* Implementation of '''RESTful API''' using '''Views''' | * Implementation of '''RESTful API''' using '''Views''' | ||
− | |||
− | |||
|- | |- | ||
Line 532: | Line 518: | ||
* Implement the '''RESTful API '''on the '''Article content type''' | * Implement the '''RESTful API '''on the '''Article content type''' | ||
− | |||
− | |||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| As an assignment | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;"| As an assignment | ||
* Implement the '''RESTful API '''on the '''Article content type''' | * Implement the '''RESTful API '''on the '''Article content type''' | ||
− | |||
− | |||
|- | |- |
Latest revision as of 13:55, 11 June 2018
|
|
Slide 1:
RESTful API Implementation |
Welcome to the spoken tutorial on RESTful API Implementation. |
Slide 2:Learning Objectives
|
In this tutorial, we will
|
Slide 3:
System requirement To record this tutorial, I am using
|
To record this tutorial, I am using
You can use any web browser as per your choice. |
Slide 4:
Pre-requisites
|
To practise this tutorial, you should have basic knowledge of Drupal.
|
Slide 5:
What is RESTful API
|
What is RESTful API?
|
Slide 5: (cont.) | For example:
|
image
|
RESTful API is a general purpose API.
can exchange data with your server. |
Show text RESTful API implementation process
|
Let us learn the RESTful API implementation process step by step.
|
Show text Step No. 1
|
Step No. 1
|
Click Extend tab | To do so, go to the Extend tab. |
Scroll down to WEB SERVICES | Scroll down and go to the WEB SERVICES section. |
Put a check mark on HAL, HTTP Basic Authentication, RESTful Web Services
and Serialization |
Put a check mark on the following modules:
HAL, HTTP Basic Authentication, RESTful Web Services and Serialization. |
Click Install button | Then click on the Install button at the bottom, to enable them. |
Show text REST UI
|
We will also need to install the REST UI module manually.
|
Show text Step No. 2
|
Step No. 2
|
Point to REST resources
|
The REST resources page appears now.
|
Scroll down
|
Scroll down.
|
Click Save configuration | Click on the Save configuration button at the bottom to save it.
|
Show text Step No. 3 | Step No. 3
|
Slide 6
|
In general, there are three kind of users that can use RESTful API.
1. anonymous user 2. authenticated user and 3. authenticated users with permission to modify content
|
Go to People tab | To do so, go to People tab. |
Click Permissions tab | Click on the Permissions tab. |
Scroll down
|
Scroll down and for AUTHENTICATED USER, put a checkmark on
Click on the Save permissions button at the bottom. |
I have enabled the authenticated users to create, edit and delete their own content.
| |
Show text Step No. 4
|
Step No. 4
|
Show text Step No. 5
|
Step No. 5
|
Click Structure → Views | To create a new view, go to Structure and Views. |
Click Add new view
Type Events_view |
Click Add view and let’s name it as Events underscore view. |
Change type as Events | Change the content of type from All to Events. |
Under REST EXPORT SETTINGS, check Provide a REST export | Under REST EXPORT SETTINGS, check Provide a REST export. |
Type REST export path as events | We will type the REST export path as events. |
Click Save and edit | Click Save and edit button at the bottom. |
Go to FORMAT → Show → Entity | Now we will set up the display of our events.
|
Choose Fields
|
In the REST export dialog box that appears, choose Fields option.
|
Click Apply | In the Row style options dialog box, keep the settings as it is.
|
Click Add | Now we can add all the fields of our Events content type.
|
In the Search box, type body | In the Search box, type body. |
Choose Body, click Add and configure fields | Choose Body from the list, then click on the Add and configure fields button. |
Click Apply | Click on the Apply button. |
Click Add | Again click on the Add button to add another field. |
Type id and choose ID | Search for id and choose ID from the list. |
Click Add and configure fields
|
Click on the Add and configure fields button.
|
Point to the path /events
|
Under PATH SETTINGS, we can see the path of our events view.
|
Show text Step No. 6
|
Step No. 6
|
Select REST export | Select REST export option.
|
Click Entity | Under FORMAT section, click on the Entity. |
Choose Fields, click Apply | Choose Fields option and click on the Apply button. |
Put check mark to all the fields
|
Check all the fields that we want in our content type.
|
Point to FIELDS | Here you can see that our required fields are added now. |
Click No path is set | Under PATH SETTINGS, we will set the path by clicking on the No path is set link. |
In Path field, type events/%
|
In the Path field, type events slash percentage sign.
|
Click Apply | Click on the Apply button at the bottom. |
Click ADVANCED | Now, in the right hand side, click on the ADVANCED option. |
Under CONTEXTUAL FILTERS, click Add | Under CONTEXTUAL FILTERS, click on the Add button. |
Type id in the search box
Choose ID |
We will add an ID for the contextual filter to refer our node.
|
Click Apply | Click on the Apply button. |
Click Apply | Keep the other settings as it is.
|
Click Save | Click on the Save button to save this configuration.
|
Later in the series, we will learn how to check our RESTful API using a REST Client.
| |
Slide 7:
Summary
|
Let us summarize.
|
Slide 8:
Assignment
|
As an assignment
|
Slide 9:
Acknowledgement
|
The video at the following link summarises the Spoken Tutorial project.
|
Slide 10:
Spoken Tutorial Workshops
|
The Spoken Tutorial Project Team conducts workshops and gives certificates to those who pass online tests.
|
Slide 11:
Acknowledgement
|
Spoken Tutorial Project is funded by
Government of India. |
This tutorial is contributed by Vishal Jindal.
|