{"id":1997,"date":"2022-06-17T19:08:38","date_gmt":"2022-06-17T19:08:38","guid":{"rendered":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2022\/06\/17\/clone-of-software-testing-interview-questions\/"},"modified":"2022-06-19T16:13:51","modified_gmt":"2022-06-19T16:13:51","slug":"api-basics-and-architecture","status":"publish","type":"post","link":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2022\/06\/17\/api-basics-and-architecture\/","title":{"rendered":"API Basics and Architecture"},"content":{"rendered":"<h3 id=\"t-1638970939482\" data-alt-text=\"1. Introduction to API\/Webservices\/Rest API \"><b>&nbsp;1.&nbsp;<b><b><b><b>Introduction to API\/Webservices\/Rest API<\/b><\/b><\/b>&nbsp;<\/b><\/b><\/h3>\n<p>Welcome you all to the brand new \u2018API Testing\u2019 blog series! In this entire series, we would be learning about REST API Automation Testing with Java, Postman. We would be starting with basics and then move to advance topics. So let\u2019s begin!!!&nbsp;<\/p>\n<h3 id=\"t-1638970939483\" data-alt-text=\"2. What you will Learn in this blog?\"><b>2. <b><b><b><b>What you will Learn in this blog?<\/b><\/b><\/b><\/b><\/b><\/h3>\n<ul>\n<li>Quickly understand \u2018Communication\u2019<\/li>\n<li>What is API<\/li>\n<li>Practical usage of API<\/li>\n<li>A very simple (raw) json<\/li>\n<li>Client-Server Architecture<\/li>\n<li>HTTP Protocol<\/li>\n<li>Difference between Webservice and API<\/li>\n<\/ul>\n<h3 data-alt-text=\"3. Quickly understand \u2018Communication\u2019\" id=\"t-1638970939484\"><b>3.&nbsp;<b><b><b><b>Quickly understand \u2018Communication\u2019<\/b><\/b><\/b><\/b><\/b><\/h3>\n<p>Before we understand API, let us quickly understand about \u2018Communication\u2019. We know that some <u>medium<\/u> is needed for communication to happen.<\/p>\n<p><span style=\"\"><img decoding=\"async\" alt=\"\" data-id=\"1964\" width=\"571\" data-init-width=\"300\" height=\"158\" data-init-height=\"83\" title=\"Image 1\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-1-300x83.jpg\" data-width=\"571\" data-height=\"158\" style=\"\" mt-d=\"-5.9950000000000045\"><\/span><span><img decoding=\"async\" alt=\"\" data-id=\"1965\" width=\"533\" data-init-width=\"300\" height=\"425\" data-init-height=\"239\" title=\"Image 2\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-2-300x239.jpg\" data-width=\"533\" data-height=\"425\" style=\"\"><\/span><span><img decoding=\"async\" alt=\"\" data-id=\"1966\" width=\"347\" data-init-width=\"207\" height=\"503\" data-init-height=\"300\" title=\"Image 3\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-3-207x300.jpg\" data-width=\"347\" data-height=\"503\" style=\"\"><\/span><\/p>\n<p>Notice above that, though WhatsApp and UPI are different software applications, still they are able to communicate with each other due to the API exposed by UPI.<\/p>\n<p>A software does not need any GUI to communicate with another software. So multiple software exchange data or communicate with each other using machine-readable interfaces, also called as Application programming Interface (API).<\/p>\n<h3 data-alt-text=\"4. What is API?\" id=\"t-1638970939488\" style=\"\"><b>4. <b><b><b><b><b>What is API<\/b><\/b><\/b><\/b>?<\/b><\/b><\/h3>\n<p>Now we can understand and define a formal definition of API. API defines a set of rules that enables communication (data transmission) between multiple software. The data exchange between multiple software may or may not involve authentication\/authorization.<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"1967\" width=\"559\" data-init-width=\"300\" height=\"322\" data-init-height=\"173\" title=\"Image 4\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-4-300x173.jpg\" data-width=\"559\" data-height=\"322\" style=\"\"><\/span><\/p>\n<p>So, let us say we open a chrome web browser and type <a href=\"https:\/\/rahulshettyacademy.com\/\" style=\"outline: none;\">https:\/\/rahulshettyacademy.com\/<\/a> on the browser address bar and Hit Enter. The request would go to an API and the API forwards the request to respective domain \u2018rahulshettyacademy\u2019. The domain (if found), responds back to API and API responds back to web browser. So API acts as an interface between web browser software and website (domain) software. The below diagram explains the same&nbsp;<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"1970\" width=\"579\" data-init-width=\"300\" height=\"141\" data-init-height=\"73\" title=\"Image 5\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-5-300x73.jpg\" data-width=\"579\" data-height=\"141\" style=\"\"><\/span><\/p>\n<p><b> <\/b><\/p>\n<h3 data-alt-text=\"5. Practical usage of API\" id=\"t-1638970939489\"><b>5. <b><b><b><b>Practical usage of API<\/b><\/b><\/b><\/b><\/b><\/h3>\n<p>Launch <a href=\"https:\/\/www.cleartrip.com\" style=\"outline: none;\" target=\"_blank\" rel=\"noopener\">https:\/\/www.cleartrip.com<\/a> and search for a Delhi-Bangalore flight. We get a lot of search results from different airline companies (Air India, Indigo etc)<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"1971\" width=\"524\" data-init-width=\"300\" height=\"234\" data-init-height=\"134\" title=\"Image 6\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-6-300x134.jpg\" data-width=\"524\" data-height=\"234\" style=\"\"><\/span><\/p>\n<p>Now, \u201ccleartrip\u201d is not an airline company, it is just a 3<sup>rd<\/sup> party software vendor (just like makemytrip, goibibo, yatra etc). Now, how come \u201ccleartrip\u201d company is having the information from different airline companies like Indigo, AirIndia etc? The answer to this question is that, \u201ccleartrip\u201d does NOT have access to the database of airlines (Indigo etc). Instead, airlines expose some of their APIs to 3<sup>rd<\/sup> party websites so that a person can buy tickets on these websites. So, cleartrip is getting the information from Spicejet or Air India through an exposed API.<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"1974\" width=\"546\" data-init-width=\"300\" height=\"262\" data-init-height=\"144\" title=\"Image 7\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-7-300x144.jpg\" data-width=\"546\" data-height=\"262\" style=\"\"><\/span><\/p>\n<p>So if a user enters source\/destination\/date &amp; searches a flight on 3<sup>rd<\/sup> party vendor (makemytrip.com), the vendor makes an API call to all the airlines and display the results in their respective website browser.<\/p>\n<p>Another practical example would be, when we try to sign-up twitter.<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"1975\" width=\"510\" data-init-width=\"300\" height=\"313\" data-init-height=\"184\" title=\"Image 8\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-8-300x184.jpg\" data-width=\"510\" data-height=\"313\" style=\"\"><\/span><\/p>\n<p>Notice above that twitter gives us options to sign-up using gmail or with apple id. So basically, google and apple have exposed their login\/sign-up APIs to twitter. So a user can login twitter using his gmail id (even though both gmail and twitter are different applications).<\/p>\n<h3 data-alt-text=\"6. A very simple (raw) json\" id=\"t-1642525980189\"><b>6.&nbsp;<\/b><b><b><b><b>A very simple (raw) json<\/b><\/b><\/b><\/b><\/h3>\n<p>Below is a typical API json <u>request<\/u> (in raw form) that is sent by cleartrip to various airline companies<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"1976\" width=\"383\" data-init-width=\"300\" height=\"334\" data-init-height=\"262\" title=\"Image 9\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-9-300x262.jpg\" data-width=\"383\" data-height=\"334\" style=\"\"><\/span><\/p>\n<p>Below is a typical API json <u>response<\/u> received by cleartrip<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"1977\" width=\"396\" data-init-width=\"295\" height=\"403\" data-init-height=\"300\" title=\"Image 10\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-10-295x300.jpg\" data-width=\"396\" data-height=\"403\" style=\"\"><\/span><\/p>\n<p>This is how API helps in communicating between different softwares.x<\/p>\n<h3 data-alt-text=\"7. Client-Server Architecture\" id=\"t-1638970939491\"><b>7. <b><b><b><b>Client-Server Architecture<\/b><\/b><\/b><\/b><\/b><\/h3>\n<p>There are 2 components in client-server architecture.<\/p>\n<ul>\n<li>Client is the consumer who wants some information from another software (a client can be a mobile phone, a desktop, laptop etc). Client sends HTTP request to server requesting some information;<\/li>\n<li>Server processes the request and responds back with HTTP response having the desired information &nbsp;<\/li>\n<\/ul>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"1978\" width=\"534\" data-init-width=\"300\" height=\"281\" data-init-height=\"158\" title=\"Image 11\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-11-300x158.jpg\" data-width=\"534\" data-height=\"281\" style=\"\"><\/span><\/p>\n<p><span style=\"font-weight: normal;\"><b><u>HTTP Protocol<\/u><\/b><\/span><\/p>\n<p>To setup the communication between client and server, we need a medium. This medium is HTTP protocol. Medium helps both the parties to communicate with each other.<\/p>\n<p>Let us consider a simple analogy to understand this. Let us suppose your native language is Hindi and your friend\u2019s native language is French. You would not understand anything in French and your friend would not understand anything in Hindi. So there should be a common medium, a common language (let\u2019s suppose English) that both, you and your friend would understand. So this is the importance of medium.<\/p>\n<p>See below diagram. The client (frontend) is generally built on HTML, CSS, Javascript languages. The backend is generally designed in different languages php, java, python etc. So, we need a common medium that both, client and server understand. This common medium is HTTP protocol. Client and server can both understand the XML, JSON data formats. HTTP protocol converts the client\/server data into XML, JSON etc. Thus,<\/p>\n<ul>\n<li>client sends the request in xml\/json format<\/li>\n<li>server sends back the response in json\/xml format<\/li>\n<\/ul>\n<p>This helps the client-server to communicate with each other using a common data format (XML, JSON).<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"1979\" width=\"508\" data-init-width=\"300\" height=\"110\" data-init-height=\"65\" title=\"Image 12\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-12-300x65.jpg\" data-width=\"508\" data-height=\"110\" style=\"\"><\/span><\/p>\n<h3 data-alt-text=\"8. Difference between Webservice and API\" id=\"t-1638970939492\"><b>8. <b><b><b><b>Difference between Webservice and API<\/b><\/b><\/b><\/b><\/b><\/h3>\n<p>The APIs that interact over HTTP protocol (need internet), we call them as webservices. For example, the cleartrip\/makemytrip is a webservice, because, in order to display the search results, they need to interact over HTTP protocol (need Internet connection) with Indigo\/AirIndia servers<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"1980\" width=\"529\" data-init-width=\"300\" height=\"129\" data-init-height=\"73\" title=\"Image 13\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-13-300x73.jpg\" data-width=\"529\" data-height=\"129\" style=\"\"><\/span><span><img decoding=\"async\" alt=\"\" data-id=\"1981\" width=\"528\" data-init-width=\"300\" height=\"236\" data-init-height=\"134\" title=\"Image 14\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-14-300x134.jpg\" data-width=\"528\" data-height=\"236\" style=\"\"><\/span><\/p>\n<p>The things that does not need internet or do not interact over HTTP protocol, we call them as API. For example, in order to work with Selenium, we need to integrate our java program with Selenium jar files. To interact with Selenium API jar files, we don\u2019t need internet or http protocol. Similarly, to read data from excel, we can integrate POI library API with our java program and start working without any internet connection.&nbsp;<\/p>\n<p><span><img decoding=\"async\" alt=\"\" data-id=\"1982\" width=\"524\" data-init-width=\"300\" height=\"117\" data-init-height=\"67\" title=\"Image 15\" loading=\"lazy\" src=\"https:\/\/rahulshettyacademy.com\/blog\/wp-content\/uploads\/2022\/06\/Image-15-300x67.jpg\" data-width=\"524\" data-height=\"117\" style=\"\"><\/span><\/p>\n<p>All webservices are APIs but reverse is not true. The weather app on your laptop\/mobile is a webservice (api) that interacts with weather server and provides us real-time weather information.<\/p>\n<p>In the next blog, we would discuss about the HTTP methods (Get, Post, Put, Delete), the components that make an HTTP request and HTTP response and the elements that constitute a REST request (URI etc).<\/p>\n<p>Thank you for reading!&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;1.&nbsp;Introduction to API\/Webservices\/Rest API&nbsp; Welcome you all to the brand new \u2018API Testing\u2019 blog series! In this entire series, we would be learning about REST API Automation Testing with Java, Postman. We would be starting with basics and then move to advance topics. So let\u2019s begin!!!&nbsp; 2. What you will Learn in this blog? Quickly [&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-1997","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\/1997","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=1997"}],"version-history":[{"count":23,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1997\/revisions"}],"predecessor-version":[{"id":2385,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1997\/revisions\/2385"}],"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=1997"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1997"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1997"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}