{"id":1920,"date":"2022-06-17T05:58:20","date_gmt":"2022-06-17T05:58:20","guid":{"rendered":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2022\/06\/17\/clone-of-api-basics-and-architecture\/"},"modified":"2022-06-19T16:15:30","modified_gmt":"2022-06-19T16:15:30","slug":"elements-of-rest-architecture","status":"publish","type":"post","link":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2022\/06\/17\/elements-of-rest-architecture\/","title":{"rendered":"Elements of REST Architecture"},"content":{"rendered":"<h3 id=\"t-1655532525892\"><b>Elements of REST Architecture<\/b>&nbsp;<\/h3>\n<p>Welcome you all to the brand new \u2018API Testing\u2019 blog series! In the previous blog, we had learned about the HTTP elements and methods. In this tutorial, we will learn about the basic REST API elements!!&nbsp;<\/p>\n<h3 id=\"t-1608133326002\"><b>1. What you will Learn in this blog ?<\/b><\/h3>\n<ul>\n<li>Difference between URL and URI<\/li>\n<li>Resource<\/li>\n<li>Base URI<\/li>\n<li>Representation<\/li>\n<li>Representation Metadata<\/li>\n<li>Difference between path parameter and query parameter<\/li>\n<li>URI composition<\/li>\n<\/ul>\n<h3 id=\"t-1655532525893\"><b>2. <b>Difference between URL and URI<\/b><\/b><\/h3>\n<p>To understand the difference between URL and URI, let us launch the homepage <a href=\"https:\/\/rahulshettyacademy.com\">https:\/\/rahulshettyacademy.com<\/a><\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2064\" width=\"509\" data-init-width=\"300\" height=\"312\" data-init-height=\"184\" title=\"Image 1\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-1-2-300x184.jpg\" data-width=\"509\" data-height=\"312\" style=\"\"><\/span><\/p>\n<p>So, to locate the \u2018rahulshettyacademy\u2019 webpage resource on the internet, we used the above URL.<\/p>\n<p>Similarly, to locate any other resource (image, link etc) on the internet, we will make use of the URL. For example, below is the link (resource) to the \u2018courses\u2019 page &nbsp;<\/p>\n<p><a href=\"https:\/\/courses.rahulshettyacademy.com\/courses\">https:\/\/courses.rahulshettyacademy.com\/courses<\/a><\/p>\n<p>So, this is the html page path or html page address, also called as URL<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2065\" width=\"529\" data-init-width=\"300\" height=\"273\" data-init-height=\"155\" title=\"Image 2\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-2-2-300x155.jpg\" data-width=\"529\" data-height=\"273\" style=\"\"><\/span><\/p>\n<p>Similarly, for the image (open the image in new tab)<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2066\" width=\"533\" data-init-width=\"300\" height=\"151\" data-init-height=\"85\" title=\"Image 3\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-3-2-300x85.jpg\" data-width=\"533\" data-height=\"151\" style=\"\"><\/span><span><img decoding=\"async\" alt=\"\" data-id=\"2069\" width=\"524\" data-init-width=\"300\" height=\"307\" data-init-height=\"176\" title=\"Image 4\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-4-2-300x176.jpg\" data-width=\"524\" data-height=\"307\" style=\"\"><\/span><\/p>\n<p>As you can see above, the URL of this image (address of the image) is<\/p>\n<p><a href=\"https:\/\/rahulshettyacademy.com\/assets\/images\/qa_slide_new.png\" style=\"outline: none;\">https:\/\/rahulshettyacademy.com\/assets\/images\/qa_slide_new.png<\/a><\/p>\n<p>Let us now understand what URI is. It is \u2018Uniform Resource Identifier\u2019. So basically, to identify any REST based webservice on internet, we use URI.<\/p>\n<p>Let us launch a sample flights webservice URI<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2070\" width=\"567\" data-init-width=\"300\" height=\"127\" data-init-height=\"67\" title=\"Image 5\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-5-2-300x67.jpg\" data-width=\"567\" data-height=\"127\" style=\"\"><\/span><\/p>\n<p><a href=\"http:\/\/ilt.mulesoft-training.com\/essentials\/united\/flights\" style=\"outline: none;\" target=\"_blank\" rel=\"noopener\">http:\/\/ilt.mulesoft-training.com\/essentials\/united\/flights<\/a><\/p>\n<p>So, this is a REST webservice URI that is used to identify flights over the internet. The above URI is without any parameter.<\/p>\n<p>We can add a URI parameter (example CLE as shown below)<\/p>\n<p><a href=\"http:\/\/ilt.mulesoft-training.com\/essentials\/united\/flights\/CLE\" style=\"outline: none;\" target=\"_blank\" rel=\"noopener\">http:\/\/ilt.mulesoft-training.com\/essentials\/united\/flights\/<b>CLE<\/b><\/a><\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2071\" width=\"532\" data-init-width=\"300\" height=\"74\" data-init-height=\"42\" title=\"Image 6\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-6-2-300x42.jpg\" data-width=\"532\" data-height=\"74\" style=\"\"><\/span><\/p>\n<p>So, in essence, URL is an address for a particular web resource like webpage or image. URI is used to identify REST webservice running on a server (with\/without parameter) or we can also say that REST webservice uses URI to identify resources<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2072\" width=\"531\" data-init-width=\"300\" height=\"156\" data-init-height=\"88\" title=\"Image 7\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-7-2-300x88.jpg\" data-width=\"531\" data-height=\"156\" style=\"\"><\/span><\/p>\n<h3 id=\"t-1655532525894\"><b>3. <b>Resource<\/b><\/b><\/h3>\n<p>Resource is simply the information or data stored on a server that is requested by the client.<\/p>\n<p>Whenever, we are trying to access something on a particular webservice\/website, we are defining a specific URI to access that \u2018thing\u2019. That \u2018thing\u2019 is called the \u2018Resource\u2019 in terms of the REST Assured.<\/p>\n<p>Below diagram is self-explanatory. When we make a REST request to server, the information that we receive back from the server is called a \u2018Resource\u2019<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2073\" width=\"553\" data-init-width=\"300\" height=\"164\" data-init-height=\"89\" title=\"Image 8\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-8-2-300x89.jpg\" data-width=\"553\" data-height=\"164\" style=\"\"><\/span><\/p>\n<p>So when we launch the site, there are 2 parts to it: domain name plus the Resource that we are trying to access <a href=\"https:\/\/rahulshettyacademy.com\/practice-project\" style=\"outline: none;\">https:\/\/rahulshettyacademy.com\/<b>practice-project<\/b><\/a><\/p>\n<p>When we hit the above page pointing to \u2018practice-project\u2019 resource on the server, we get back the information of the \u2018practice-project\u2019 page.<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2074\" width=\"532\" data-init-width=\"300\" height=\"257\" data-init-height=\"145\" title=\"Image 9\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-9-2-300x145.jpg\" data-width=\"532\" data-height=\"257\" style=\"\"><\/span><\/p>\n<p>Similarly \u2018lifetime-access\u2019 is another resource inside the same domain, see below<\/p>\n<p><a href=\"https:\/\/rahulshettyacademy.com\/lifetime-access\" style=\"outline: none;\">https:\/\/rahulshettyacademy.com\/<b>lifetime-access<\/b><\/a><!--[if !supportLineBreakNewLine]--><!--[endif]--><span><img decoding=\"async\" alt=\"\" data-id=\"2075\" width=\"528\" data-init-width=\"300\" height=\"424\" data-init-height=\"241\" title=\"Image 10\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-10-2-300x241.jpg\" data-width=\"528\" data-height=\"424\" style=\"\"><\/span><\/p>\n<h3 id=\"t-1655532525895\"><b>4. <b><b>Base URI<\/b><\/b><\/b><\/h3>\n<p>The host domain of any website never changes. It is called as \u2018Base URI\u2019<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2076\" width=\"574\" data-init-width=\"300\" height=\"214\" data-init-height=\"112\" title=\"Image 11\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-11-2-300x112.jpg\" data-width=\"574\" data-height=\"214\" style=\"\"><\/span><\/p>\n<p>Notice below that all of them have same base URI but different resource<\/p>\n<p><a href=\"https:\/\/rahulshettyacademy.com\/practice-project\" style=\"outline: none;\"><b>https:\/\/rahulshettyacademy.com<\/b>\/practice-project<\/a><\/p>\n<p><a href=\"https:\/\/rahulshettyacademy.com\/lifetime-access\" style=\"outline: none;\"><b>https:\/\/rahulshettyacademy.com<\/b>\/lifetime-access<\/a><\/p>\n<p><a href=\"https:\/\/rahulshettyacademy.com\/blog\/\" style=\"outline: none;\"><b>https:\/\/rahulshettyacademy.com<\/b>\/blog\/<\/a>Similarly see below 2 examples<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2077\" width=\"529\" data-init-width=\"300\" height=\"155\" data-init-height=\"88\" title=\"Image 12\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-12-2-300x88.jpg\" data-width=\"529\" data-height=\"155\" style=\"\"><\/span><span><img decoding=\"async\" alt=\"\" data-id=\"2079\" width=\"529\" data-init-width=\"300\" height=\"113\" data-init-height=\"64\" title=\"Image 13\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-13-2-300x64.jpg\" data-width=\"529\" data-height=\"113\" style=\"\"><\/span><\/p>\n<h3 id=\"t-1655532525896\"><b>5. <b>Representation<\/b><\/b><\/h3>\n<p>Now, we know that, the \u2018Resource\u2019 is actual data or information. Over the internet, this resource can be represented as XML, JSON, HTML, CSS etc.<\/p>\n<p>&nbsp;Recall that, whenever we send a request from the browser, the request goes to the server and the server sends back the resource\/data\/information back to the client browser. The browser represents this data to the client in the form of webpage comprising of HTML, CSS etc.<span><img decoding=\"async\" alt=\"\" data-id=\"2078\" width=\"524\" data-init-width=\"300\" height=\"176\" data-init-height=\"101\" title=\"Image 14\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-14-2-300x101.jpg\" data-width=\"524\" data-height=\"176\" style=\"\"><\/span><\/p>\n<h3 id=\"t-1655532525897\"><b>6. <b>Representation Metadata<\/b><\/b><\/h3>\n<p>The extra data which is coming with the resource. So, along with the Representation data, we will always get the metadata from the server. For example, the Date when the resource was fetched, type of protocol, cache etc.<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2080\" width=\"554\" data-init-width=\"300\" height=\"131\" data-init-height=\"71\" title=\"Image 15\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-15-2-300x71.jpg\" data-width=\"554\" data-height=\"131\" style=\"\"><\/span><\/p>\n<p>Look at the below \u2018Response\u2019 header metadata. Some of the metadata information that we can see is: Date, Server info, cookie etc<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2081\" width=\"556\" data-init-width=\"300\" height=\"443\" data-init-height=\"239\" title=\"Image 16\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-16-1-300x239.jpg\" data-width=\"556\" data-height=\"443\" style=\"\"><\/span><\/p>\n<h3 id=\"t-1655532525898\"><b>7. <b><b>Difference between path parameter and query parameter<\/b><\/b><\/b><\/h3>\n<p>To understand the difference, consider below 4 cases (some of these are dummy urls). In the first case, we are launching base url<\/p>\n<p><a href=\"http:\/\/www.twitter.com\/india\" target=\"_blank\" rel=\"noopener\">twitter.com<\/a> (base URL)In the second case, we are appending a resource \u2018india\u2019 to base URL <a href=\"http:\/\/www.twitter.com\/india\" target=\"_blank\" rel=\"noopener\">twitter.com\/<b>india<\/b><\/a><\/p>\n<p>In the third case, we are appending path parameter \u2018profile\u2019, we can use this path parameter to fetch all the profiles from entire \u2018india\u2019 location<\/p>\n<p><a href=\"http:\/\/www.twitter.com\/india\/profile\" style=\"outline: none;\" target=\"_blank\" rel=\"noopener\">twitter.com\/india\/<b>profile<\/b><\/a><\/p>\n<p>In the fourth case, we are appending query parameter \u2018profile?=delhi\u2019, we can use this filter parameter to fetch the profiles only from \u2018delhi\u2019 location<\/p>\n<p><a href=\"http:\/\/www.twitter.com\/india\/profile?=delhi\" style=\"outline: none;\" target=\"_blank\" rel=\"noopener\">twitter.com\/india\/profile<b>?=delhi<\/b><\/a><b><\/b><\/p>\n<h3 id=\"t-1655532525899\"><b>8. <b><b><b>URI composition<\/b><\/b><\/b><\/b><\/h3>\n<p>Let us search for any keyword in google&nbsp;<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2082\" width=\"527\" data-init-width=\"300\" height=\"183\" data-init-height=\"104\" title=\"Image 17\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-17-1-300x104.jpg\" data-width=\"527\" data-height=\"183\" style=\"\"><\/span><\/p>\n<p>The syntax of complete URI can be constructed as below:<\/p>\n<p>URI = protocol:\/\/Domain\/Resource[? query parameter in the form of key=value pair]&amp;[another query parameter]\u2026<\/p>\n<p>Note that the server can have multiple resources under the same path (just like we can have multiple files inside the same directory). Since each resource has some physical location on the server, we use query parameter to inform server which resource we want to get.<\/p>\n<p>For example, we can construct a URI to query the users on page 1<\/p>\n<p><a href=\"https:\/\/reqres.in\/api\/users?page=1\" style=\"outline: none;\" target=\"_blank\" rel=\"noopener\">https:\/\/reqres.in\/api\/users?page=1<\/a><\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2083\" width=\"553\" data-init-width=\"300\" height=\"302\" data-init-height=\"164\" title=\"Image 18\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-18-1-300x164.jpg\" data-width=\"553\" data-height=\"302\" style=\"\"><\/span><\/p>\n<p>Similarly we can query the users on page 5, see below<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"2084\" width=\"529\" data-init-width=\"300\" height=\"102\" data-init-height=\"58\" title=\"Image 19\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-19-1-300x58.jpg\" data-width=\"529\" data-height=\"102\" style=\"\"><\/span><\/p>\n<p>So, this was all about the various elements used in REST API terminology. We will next start with Postman (test REST APIs manually).<\/p>\n<p>Thank you for reading!<\/p>\n<p><b><\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Elements of REST Architecture&nbsp; Welcome you all to the brand new \u2018API Testing\u2019 blog series! In the previous blog, we had learned about the HTTP elements and methods. In this tutorial, we will learn about the basic REST API elements!!&nbsp; 1. What you will Learn in this blog ? Difference between URL and URI Resource [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2293,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1920","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","post-wrapper","thrv_wrapper"],"_links":{"self":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1920","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1920"}],"version-history":[{"count":22,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1920\/revisions"}],"predecessor-version":[{"id":2301,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1920\/revisions\/2301"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/media\/2293"}],"wp:attachment":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}