Difference between revisions of "Drupal/C4/RESTful-API-with-a-REST-Client/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.062cm;padding-right:0.191cm;"| <cent...") |
|||
(One intermediate revision by one other user not shown) | |||
Line 15: | Line 15: | ||
* What is REST client | * What is REST client | ||
* Retrieve data - GET method | * Retrieve data - GET method | ||
− | * Create a new node - POST method | + | * Create a new '''node''' - POST method |
− | * Modify an existing node - PATCH method | + | * Modify an existing '''node''' - PATCH method |
− | * Delete an existing node - DELETE method | + | * Delete an existing '''node''' - DELETE method |
− | + | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| In this tutorial, we will learn about '''REST client. ''' | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| In this tutorial, we will learn about '''REST client. ''' | ||
Line 29: | Line 28: | ||
* Modify an existing node using '''PATCH method''' and | * Modify an existing node using '''PATCH method''' and | ||
* Delete an existing node using '''DELETE method''' | * Delete an existing node using '''DELETE method''' | ||
− | |||
− | |||
|- | |- | ||
Line 43: | Line 40: | ||
* Postman as a REST Client | * Postman as a REST Client | ||
* Firefox web browser | * Firefox web browser | ||
− | |||
− | |||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;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.062cm;padding-right:0.191cm;"| To record this tutorial, I am using | ||
Line 78: | Line 73: | ||
|- | |- | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| Open '''Drupa8''' site | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| Open '''Drupa8''' site | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| First we will confirm whether RESTful API is implemented in our '''Drupal8''' site. | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| First we will confirm whether '''RESTful API''' is implemented in our '''Drupal8''' site. |
Line 88: | Line 83: | ||
− | Here you can see that '''RESTful API''' is implemented in the '''Events''' | + | Here you can see that '''RESTful API''' is implemented in the '''Events content type'''. |
|- | |- | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| Show text '''Postman Client''' | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| Show text '''Postman Client''' | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| Note that we have already learnt to implement the '''RESTful API '''earlier. | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| Note that we have already learnt to implement the '''RESTful API '''earlier. |
Line 106: | Line 101: | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| Slide 6: '''Postman Client''' | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| Slide 6: '''Postman Client''' | ||
− | * It is a powerful HTTP client for testing web services | + | * It is a powerful '''HTTP client''' for testing '''web services''' |
* For installing '''Postman client, '''see''' Additional reading material''' link | * For installing '''Postman client, '''see''' Additional reading material''' link | ||
Line 122: | Line 117: | ||
− | But most of the steps are applicable to any other '''Drupal''' | + | But most of the steps are applicable to any other '''Drupal installation''', as well. |
|- | |- | ||
Line 130: | Line 125: | ||
|- | |- | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| Choose '''GET''' | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| Choose '''GET''' | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| First we will learn to retrieve data for '''Anonymous users''' using '''GET''' | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| First we will learn to retrieve data for '''Anonymous users''' using '''GET method'''. |
Line 200: | Line 195: | ||
− | You can see here the content of that particular node is retrieved. | + | You can see here the content of that particular '''node''' is retrieved. |
Line 210: | Line 205: | ||
Choose '''POST''' | Choose '''POST''' | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| Next let us learn to create a new '''node''' for '''Authenticated users''' using '''POST''' | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| Next let us learn to create a new '''node''' for '''Authenticated users''' using '''POST method'''. |
Line 351: | Line 346: | ||
− | We will use this '''UID''' in the postman client to modify this node. | + | We will use this '''UID''' in the postman client to modify this '''node'''. |
Line 361: | Line 356: | ||
Click plus button | Click plus button | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| Next let us learn to modify a node for '''Authenticated users''' using '''PATCH method.''' | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| Next let us learn to modify a '''node''' for '''Authenticated users''' using '''PATCH method.''' |
Line 384: | Line 379: | ||
− | The '''UID''' of this ''' | + | The '''UID''' of this '''post''' is '''100'''. |
− | We will enter the URL of the node 100. | + | We will enter the URL of the '''node 100'''. |
|- | |- | ||
Line 465: | Line 460: | ||
− | In this code we modify the values for both the title and the body fields. | + | In this code we modify the values for both the '''title''' and the '''body fields'''. |
Line 489: | Line 484: | ||
Point to the first event | Point to the first event | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| Let us check the content in our '''Drupal '''website | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| Let us check the content in our '''Drupal '''website. |
Line 511: | Line 506: | ||
− | I will choose node 100 which was created by me as an authenticated user. | + | I will choose '''node 100''' which was created by me as an '''authenticated user'''. |
Line 579: | Line 574: | ||
|- | |- | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| This is all about | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| This is all about managing content through '''Postman client'''. |
Line 593: | Line 588: | ||
* '''Postman client '''as a REST client | * '''Postman client '''as a REST client | ||
* Managing content through '''Postman client '''using '''GET, POST, PATCH '''and''' DELETE '''methods | * Managing content through '''Postman client '''using '''GET, POST, PATCH '''and''' DELETE '''methods | ||
− | |||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| Let us summarize. | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| Let us summarize. | ||
Line 600: | Line 594: | ||
In this tutorial, we have learnt about- | In this tutorial, we have learnt about- | ||
− | * '''Postman client '''as a REST client and | + | * '''Postman client '''as a '''REST client''' and |
− | * Managing content through '''Postman client''' using '''GET, POST, PATCH '''and''' DELETE ''' | + | * Managing content through '''Postman client''' using '''GET, POST, PATCH '''and''' DELETE methods''' |
− | + | ||
− | + | ||
|- | |- | ||
Line 612: | Line 604: | ||
* Create some new '''articles''' through '''REST Client''' | * Create some new '''articles''' through '''REST Client''' | ||
* Modify the '''articles''' using '''PATCH method''' | * Modify the '''articles''' using '''PATCH method''' | ||
− | |||
− | |||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| As an assignment | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.062cm;padding-right:0.191cm;"| As an assignment | ||
* Create some new '''articles''' through '''REST client '''and | * Create some new '''articles''' through '''REST client '''and | ||
* Modify the '''articles''' using '''PATCH method''' | * Modify the '''articles''' using '''PATCH method''' | ||
− | |||
− | |||
|- | |- |
Latest revision as of 16:48, 11 June 2018
|
|
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 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.
|