Drupal/C4/RESTful-API-with-a-REST-Client/English
|
|
Slide 1:
RESTful API with a REST Client |
Welcome to the spoken tutorial on RESTful API with a REST Client. |
Slide 2:Learning Objectives
|
In this tutorial, we will learn about REST client.
|
Slide 3:
System requirement To record this tutorial, I am using
|
To record this tutorial, I am using
You can use any REST client and web browser as per your choice. |
Slide 4:
Pre-requisites
|
To practise this tutorial, you should have basic knowledge of Drupal.
|
Open Drupa8 site | First we will confirm whether RESTful API is implemented in our Drupal8 site.
|
Go to Structure and Views | Then go to Structure and Views.
|
Show text Postman Client | Note that we have already learnt to implement the RESTful API earlier.
|
Slide 6: Postman Client
|
Postman is a powerful HTTP client for testing web services.
To install the Postman client, refer to the Additional reading material link of this tutorial. |
Show text Bitnami Drupal Stack
|
The following steps are applicable to Bitnami Drupal Stack.
|
Open Postman Client | Let us open the Postman client. |
Choose GET | First we will learn to retrieve data for Anonymous users using GET method.
|
Type http://localhost/drupal/events
|
Recall that earlier we had implemented the RESTful API on our Events content type.
|
Click Send
|
Now click on the Send button at the top right corner.
|
Click plus button
|
Next let us learn to retrieve a single node.
|
Click Send
|
Click on the Send button.
|
Click plus button
|
Next let us learn to create a new node for Authenticated users using POST method.
Choose POST from the drop-down list. |
Type http://localhost:8080/drupal/entity/node?_format=hal+json
Highlight localhost:8080
|
Type the path as shown.
|
Change Type as Basic Auth | Under Authorization, we will change the Type as Basic Authentication. |
Type username and password | Now we will give the username and password of our Drupal website. |
Click Preview Request | Click on the Preview Request button at the left hand side to update our request. |
Click Headers tab
|
Click on the Headers tab.
|
Type Content-Type as application/hal+json | We will set the Content-Type to application/hal+json. |
Click Body tab | Now we will go to the Body tab. |
Choose raw | Let us change the data format as raw. |
{
"_links": { "type": { "href": "http://localhost:8080:8080/drupal/rest/type/node/events" }
"title":[ { "value": "Created by an authenticated user!!!" } ],
{ "value": " This is an event!!!" } ]
|
Here we must declare the required title and type fields.
|
Click Send | Click on the Send button at the top right corner. |
Point to the json code | If the content is successfully posted, you can see the json code of this content at the bottom. |
Switch to Drupal site
|
We can also check the content in our Drupal website.
|
Switch to Postman Client
|
Next let us learn to modify a node for Authenticated users using PATCH method.
|
Choose PATCH | Choose PATCH from the drop-down list. |
Type http://localhost:8080/drupal/node/100
|
We will enter the URL of the node which we want to modify.
|
Change Type as Basic Auth | Under Authorization, we will change the Type as Basic Authentication. |
Type username and password | Now we will give the username and password of our Drupal website. |
Click Preview Request | Click on the Preview Request button at the left hand side. |
Click Headers tab
|
Click on the Headers tab.
|
Type Content-Type as application/hal+json | We will set the Content-Type to application/hal+json. |
Click Body tab | Now we will go to the Body tab. |
Choose raw | Change the data format as raw. |
Type
{ "_links": { "type": { "href": "http://localhost:8080/drupal/rest/type/node/events" }
"title":[ { "value": "Changed by PATCH!!!" } ],
{ "value": " The value is changed by patch method!!!" } ]
|
And type the following code here.
|
Click Send | Then click on the Send button at the top right corner. |
Point to Status OK | You can see the Status as 200 OK which means the content is modified. |
Switch to Drupal site
|
Let us check the content in our Drupal website.
|
Choose node 8
|
Next let us learn to delete an existing node for Authenticated users using DELETE method.
|
Switch to Postman Client
|
Switch back to the Postman client.
|
Choose DELETE | Choose DELETE from the drop-down list. |
Type http://localhost:8080/drupal/node/8 | We will enter the URL of the node which we want to delete. |
Change Type as Basic Auth | Under Authorization, we will change the Type as Basic Authentication. |
Type username and password | Now we will give the username and password of our Drupal website. |
Click Preview Request | Click on the Preview Request button at the left hand side. |
Click Headers tab | Then click on the Headers tab. |
Type Content-Type as application/hal+json | We will set the Content-Type to application/hal+json. |
Click Send | Click on the Send button at the top right corner. |
Point to Status 204 No content | You can see the Status as 204 No content which means the content is deleted. |
Switch to Drupal site | Switch back to our Drupal site. |
Refresh the page | Let us refresh the page. |
Point to Page not found | We can see that the node is successfully deleted.
|
This is all about the managing content through Postman client.
| |
Slide 7:
Summary In this tutorial, we have learnt about-
|
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.
|