{"id":125,"date":"2018-03-22T09:48:00","date_gmt":"2018-03-22T08:48:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/2018\/03\/22\/restful-web-services-tutorial-2-setting-up-a-rest-client\/"},"modified":"2020-11-05T14:12:05","modified_gmt":"2020-11-05T13:12:05","slug":"restful-web-services-tutorial-2-setting-up-a-rest-client","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/restful-web-services-tutorial-2-setting-up-a-rest-client\/","title":{"rendered":"RESTful Web Services Tutorial 2 &#8211; Setting up a REST Client"},"content":{"rendered":"<div style=\"color: #555555; font-size: 18px; line-height: 30px; text-align: justify;\">\n<div style=\"font-family: 'segoe ui';\">In this lesson, we would cover the following<\/p>\n<ol>\n<li><a href=\"http:\/\/kindsonthegenius.blogspot.com\/#t1\">Review of Tutorial 1<\/a><\/li>\n<li><a href=\"http:\/\/kindsonthegenius.blogspot.com\/#t2\">Overview of REST Client<\/a><\/li>\n<li><a href=\"http:\/\/kindsonthegenius.blogspot.com\/#t3\">Setup of Postman REST Client<\/a><\/li>\n<li><a href=\"http:\/\/kindsonthegenius.blogspot.com\/#t4\">Getting used to Advanced REST Interface <\/a> <\/li>\n<li><a href=\"http:\/\/kindsonthegenius.blogspot.com\/#t5\">Performing GET Operations<\/a><\/li>\n<li><a href=\"http:\/\/kindsonthegenius.blogspot.com\/#t6\">Next Steps&nbsp;<\/a><\/li>\n<\/ol>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/4.bp.blogspot.com\/-uaRVmtiDwuk\/WrN6E5nuq0I\/AAAAAAAABeA\/b1UEjr2kkWcTV_sP4b35-Y-PmnNm3dbMgCLcBGAs\/s1600\/How%2Bto%2BSetup%2BAdvanced%2BREST%2BClient.jpg\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" data-original-height=\"819\" data-original-width=\"1345\" height=\"194\" src=\"https:\/\/4.bp.blogspot.com\/-uaRVmtiDwuk\/WrN6E5nuq0I\/AAAAAAAABeA\/b1UEjr2kkWcTV_sP4b35-Y-PmnNm3dbMgCLcBGAs\/s320\/How%2Bto%2BSetup%2BAdvanced%2BREST%2BClient.jpg\" width=\"320\" \/><\/a><\/div>\n<p><b><\/p>\n<h3>1. Review of <a href=\"https:\/\/kindsonthegenius.com\/blog\/restful-web-services-tutorial-1-creating-a-rest-api-in-visual-studio-net-c\/\" target=\"_blank\" rel=\"noopener noreferrer\">Tutorial 1<\/a><\/h3>\n<p><\/b><br \/>&nbsp;In Tutorial 1, we build a REST Web service from the scratch using Visual Studio and C#. It was quite a straight forward procedure. In case, you need to review it, that would be fine so you can get used to it.<br \/>Also, if you have not taken <a href=\"https:\/\/kindsonthegenius.com\/blog\/restful-web-services-tutorial-1-creating-a-rest-api-in-visual-studio-net-c\/\" target=\"_blank\" rel=\"noopener noreferrer\">Tutorial 1<\/a>, you need to go back and take it because you need it to get a clearer understanding of this Tutorial 2.<\/p>\n<p> <ins data-ad-client=\"ca-pub-7041870931346451\" data-ad-format=\"fluid\" data-ad-layout=\"in-article\" data-ad-slot=\"8227894917\" style=\"display: block; text-align: center;\"><\/ins><br \/><b><\/p>\n<h3>2. Overview of REST Client<\/h3>\n<p><\/b><br \/>I am sure that by now the concept of REST web service is very clear, a service that is accessible over HTTP and conforms to the REST architechtural style.<\/p>\n<p>So the question is,<br \/><span style=\"color: red;\">&#8220;what is the difference between a REST web service and other services?&#8221;<\/span><br \/>the differnce is that for a service to be considered a REST web service, it should conform to the following 4 criteria<\/p>\n<ol>\n<li>it must have resource-based URLs &#8211; <span style=\"color: #274e13;\"><b>Level 1<\/b><\/span><\/li>\n<li>it must use the correct HTTP verbs (GET, PUT, POST, DELETE) &#8211; <b><span style=\"color: #274e13;\">Level 2<\/span><\/b><\/li>\n<li>it must return the right status-codes &#8211;<b><span style=\"color: #274e13;\"> Level 2<\/span><\/b><\/li>\n<li>it must be HATEOAS-compliant &#8211; <span style=\"color: #274e13;\"><b>Level 3<\/b><\/span><\/li>\n<\/ol>\n<p>This four criteria make up the <a href=\"https:\/\/kindsonthegenius.com\/blog\/richardsons-maturity-model-for-restful-apis\/\" target=\"_blank\" rel=\"noopener noreferrer\">Richardson&#8217;s Maturity Model<\/a>. You can read it up <a href=\"https:\/\/kindsonthegenius.com\/blog\/richardsons-maturity-model-for-restful-apis\/\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/p>\n<p>For us to test these wether our API meets up these four criteria, just thebrowser would not do. We need a REST Client application<\/p>\n<p><b><\/p>\n<h3>3. Setup of Advanced REST Client<\/h3>\n<p><\/b><br \/>In this demo, we are going to use Advanced Rest Client from now till the rest of this tutorial. Advanced Rest Client is a free application provided as a plugin to Chrome browser. <\/p>\n<p>Visit the Chrome Store on this link <a href=\"https:\/\/chrome.google.com\/webstore\/category\/extensions\">https:\/\/chrome.google.com\/webstore\/category\/extensions<\/a><br \/>Search for Advanced REST Client. Then select it.<br \/>The window is shown as in Figure 1<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/1.bp.blogspot.com\/-gll-qUGYGRU\/WrMjBIns3MI\/AAAAAAAABc8\/EdmRvdKQ5T8tmIsDEtlGpkC3seBT8Aa8ACLcBGAs\/s1600\/Advanced%2BRest%2BClient.jpg\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" data-original-height=\"801\" data-original-width=\"1450\" height=\"352\" src=\"https:\/\/1.bp.blogspot.com\/-gll-qUGYGRU\/WrMjBIns3MI\/AAAAAAAABc8\/EdmRvdKQ5T8tmIsDEtlGpkC3seBT8Aa8ACLcBGAs\/s640\/Advanced%2BRest%2BClient.jpg\" width=\"640\" \/><\/a><\/div>\n<div style=\"clear: both; text-align: center;\">Figure 1: Advanced REST Client <\/div>\n<p>Click on Add To Chrome on the upper left (Blue Button). It downloads and adds as an extention to chrome.<br \/>You will see another tab opens and you can see Advanced Rest Client (a blue Icon) in the list of apps as shown in Figure 2<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/4.bp.blogspot.com\/-xTtzWbMcV3M\/WrMj-lb6ljI\/AAAAAAAABdI\/HlyAexxOXLEnkETRZi9nCcsLC9yJ49joACLcBGAs\/s1600\/Figure%2B2%2B-%2BARC%2Badded%2Bto%2Bchrome.jpg\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" data-original-height=\"806\" data-original-width=\"1351\" height=\"380\" src=\"https:\/\/4.bp.blogspot.com\/-xTtzWbMcV3M\/WrMj-lb6ljI\/AAAAAAAABdI\/HlyAexxOXLEnkETRZi9nCcsLC9yJ49joACLcBGAs\/s640\/Figure%2B2%2B-%2BARC%2Badded%2Bto%2Bchrome.jpg\" width=\"640\" \/>&nbsp;<\/a><\/div>\n<div style=\"clear: both; text-align: center;\">Figure 2 &#8211; Advanced REST Client Added to Chrome<\/div>\n<p>Click on it and then Click on Launch App in the next window that opens<br \/>The Advanced REST Client window opens as shown in Figure 3<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/1.bp.blogspot.com\/-HTm0nEp0SeY\/WrMknjqwvJI\/AAAAAAAABdQ\/Ho1Dwz-PH0McKislpR6aJGAwai9I4ZJIQCLcBGAs\/s1600\/Figure%2B3%2B-%2BARC%2BWindow.jpg\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" data-original-height=\"783\" data-original-width=\"1243\" height=\"402\" src=\"https:\/\/1.bp.blogspot.com\/-HTm0nEp0SeY\/WrMknjqwvJI\/AAAAAAAABdQ\/Ho1Dwz-PH0McKislpR6aJGAwai9I4ZJIQCLcBGAs\/s640\/Figure%2B3%2B-%2BARC%2BWindow.jpg\" width=\"640\" \/><\/a><\/div>\n<div style=\"clear: both; text-align: center;\">Figure 3: Advanced REST Client Window <\/div>\n<p>Let&#8217;s now take some time to get used to the Advanced REST Client interface<\/p>\n<p>  <ins data-ad-client=\"ca-pub-7041870931346451\" data-ad-format=\"fluid\" data-ad-layout=\"in-article\" data-ad-slot=\"8227894917\" style=\"display: block; text-align: center;\"><\/ins> <br \/><b><\/p>\n<h3>4. Getting used to Advanced REST Interface<\/h3>\n<p><\/b><br \/>Take not of the following parts of the Window<br \/>Method List: This is the list of HTTP methods. The first item here is GET but you could drop down to see a list of other methods. You need to select this depending on the type of request you want to make<\/p>\n<p><b><i>Request URL<\/i>: <\/b>This is where you enter the URL containing the API you want to access. The Request URL ends with the port number if ther is a port number<\/p>\n<p><i><b>Path<\/b>:<\/i> This is path that to a resource which may come after the Request URL. This path is everything following the port number.<\/p>\n<p>Query Parameters<b>:<\/b> This is URL query parameters. It is used if the request contains query paramters.<\/p>\n<p>For example<\/p>\n<div style=\"text-align: center;\"><span style=\"color: blue;\">http:\/\/kindsonthegenius.blogspot.hu\/getpost?id=50<\/span><\/div>\n<p>In the above example the URL parameter is id and the value is 50.<\/p>\n<p><i><b>Send Button<\/b><\/i>: Click to sent the request<\/p>\n<p><i><b>Headers<\/b><\/i>: HTTP headers define the operating parameters or a HTTP transaction.For example, encoding and character set.<\/p>\n<p><b><i>Body<\/i>: <\/b>Request body. This tab shows for POST, PUT and DELETE request types. It appears between the Headers tabe and the variables tab.<\/p>\n<p><i><b>Varibles<\/b><\/i>: This is needed if there are additional variables needed to be sent along with the request<\/p>\n<p><b><\/p>\n<h3>5. Performing GET Operations<\/h3>\n<p><\/b><br \/>You could see how it works by entering www.google.com in the request URL section and pressing Send. You will observe that you have a response of 200 OK.<\/p>\n<p>We are now going to use Advanced REST Client to test the API we built in <a href=\"https:\/\/kindsonthegenius.com\/blog\/restful-web-services-tutorial-1-creating-a-rest-api-in-visual-studio-net-c\/\" target=\"_blank\" rel=\"noopener noreferrer\">Tutorial 1<\/a>.<br \/>Open the Solution we created in <a href=\"https:\/\/kindsonthegenius.com\/blog\/restful-web-services-tutorial-1-creating-a-rest-api-in-visual-studio-net-c\/\" target=\"_blank\" rel=\"noopener noreferrer\">Tutorial 1<\/a><\/p>\n<p><a href=\"http:\/\/kindsonthegenius.blogspot.com\/2018\/03\/restful-web-services-tutorial-source.html\" target=\"_blank\" rel=\"noopener noreferrer\">(Download the Solution from here)<\/a><\/p>\n<p>Run it and make sure it it running<\/p>\n<p><i>We would carry out to REST API requests:<\/i><\/p>\n<ul>\n<li>GET request to return all employees<\/li>\n<li>GET request to return employees by a given ID<\/li>\n<\/ul>\n<p>For the first task: In the Request URL section, enter the URL (make sure to change the port number, <span style=\"color: red;\">24675 <\/span>to the one you have in your browser)<\/p>\n<p><span style=\"color: blue;\">http:\/\/localhost:24675\/api\/Employee\/getEmployees<\/span><\/p>\n<p>Your output would be as shown in Figure 4<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/3.bp.blogspot.com\/-9_RidNnK6zs\/WrN3HLFE77I\/AAAAAAAABdk\/1IO7C8IMXlwtX-1y_ilQjoxHrooYsHOdwCLcBGAs\/s1600\/Figure%2B4%2B-%2BGEt%2BREquest%2B1.jpg\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" data-original-height=\"741\" data-original-width=\"1105\" height=\"428\" src=\"https:\/\/3.bp.blogspot.com\/-9_RidNnK6zs\/WrN3HLFE77I\/AAAAAAAABdk\/1IO7C8IMXlwtX-1y_ilQjoxHrooYsHOdwCLcBGAs\/s640\/Figure%2B4%2B-%2BGEt%2BREquest%2B1.jpg\" width=\"640\" \/><\/a><\/div>\n<div style=\"clear: both; text-align: center;\">Figure 4: GET Request for all Employees<\/div>\n<p>For the second task: In the Request URL section, paste the URL below (make sure to change the port number, <span style=\"color: red;\">24675 <\/span>to the one you have in your browser)<\/p>\n<p><span style=\"color: blue;\">http:\/\/localhost:<span style=\"color: red;\">24675<\/span>\/api\/Employee\/getEmployeeById\/2<\/span><\/p>\n<p><i>Observe that the the URL is automatically divided into two paths<\/i><\/p>\n<ul>\n<li>Request URL: <span style=\"color: blue;\">http:\/\/localhost:<span style=\"color: red;\">24675<\/span><\/span><\/li>\n<li>Path: <span style=\"color: blue;\"><span style=\"color: red;\"><\/span>\/api\/Employee\/getEmployeeById\/2<\/span><\/li>\n<\/ul>\n<p>You will get similar output, but with just one record as shown in Figure 5<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/2.bp.blogspot.com\/-ksD2b_5xoug\/WrN4Ic1cq3I\/AAAAAAAABd0\/VDhEBjpPshsK8P3pwS-x6TxDn5Gko6RPQCLcBGAs\/s1600\/Figure%2B5%2B-%2BGEt%2BREquest%2B2.jpg\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" data-original-height=\"797\" data-original-width=\"1117\" height=\"456\" src=\"https:\/\/2.bp.blogspot.com\/-ksD2b_5xoug\/WrN4Ic1cq3I\/AAAAAAAABd0\/VDhEBjpPshsK8P3pwS-x6TxDn5Gko6RPQCLcBGAs\/s640\/Figure%2B5%2B-%2BGEt%2BREquest%2B2.jpg\" width=\"640\" \/> <\/a>Figure 5: GET Request with for particular ID <\/div>\n<p>If you got this correctly, then be sure you will reach great heights! You have successufully completed Tutorial 2. Let&#8217;s keep moving gradually untill you become an expert in REST APIs!<\/p>\n<p><b><\/p>\n<h3>6. Next Steps&nbsp;<\/h3>\n<p><\/b><br \/>Now that you have completed Tutorial 2 of RESTful Web Service, congratulations! Note that in we have written a REST API that accepts only a GET request.<br \/>In the next tutorial, we would write more actions (remember actions are simply methods or functions) that would accept a POST request and create a new Employee object.<br \/>Then we would also write another method to perform a PUT operation and so on<\/p>\n<p>For now, thanks for reading and do leave a comment to let me know your observations \ud83d\ude05\ud83d\ude03   <\/p><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this lesson, we would cover the following Review of Tutorial 1 Overview of REST Client Setup of Postman REST Client Getting used to Advanced &hellip; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[289],"tags":[],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/125"}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=125"}],"version-history":[{"count":3,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/125\/revisions"}],"predecessor-version":[{"id":1752,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/125\/revisions\/1752"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}