{"id":121,"date":"2018-03-26T14:12:00","date_gmt":"2018-03-26T14:12:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/2018\/03\/26\/restful-web-services-tutorial-4-testing-the-rest-apis-using-advanced-rest-client\/"},"modified":"2020-11-05T14:14:54","modified_gmt":"2020-11-05T13:14:54","slug":"restful-web-services-tutorial-4-testing-the-rest-apis-using-advanced-rest-client","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/restful-web-services-tutorial-4-testing-the-rest-apis-using-advanced-rest-client\/","title":{"rendered":"RESTful Web Services Tutorial 4 &#8211; Testing the REST APIs using Advanced REST Client"},"content":{"rendered":"<div style=\"font-size: 18px; line-height: 30px; text-align: justify;\">\n<div style=\"font-family: 'segoe ui';\">\n<div style=\"color: #555555;\">Good to see you again! It is good to know that you have come this far. Thumbs up to you! \ud83d\udc4d\ud83d\udc4d\ud83d\udc4d\ud83d\udc4d<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/2.bp.blogspot.com\/-QQw1BCf9Zac\/Wrj9nj_guNI\/AAAAAAAABmA\/Z_7Qqx9-0wE4uR-kOnONKNCiyKuwleZOQCLcBGAs\/s1600\/Tutorial%2B4%2B-%2BTesting%2BREST%2BAPI%2Bwith%2BAdvanced%2BREST%2Bclient.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/2.bp.blogspot.com\/-QQw1BCf9Zac\/Wrj9nj_guNI\/AAAAAAAABmA\/Z_7Qqx9-0wE4uR-kOnONKNCiyKuwleZOQCLcBGAs\/s320\/Tutorial%2B4%2B-%2BTesting%2BREST%2BAPI%2Bwith%2BAdvanced%2BREST%2Bclient.jpg\" width=\"320\" height=\"180\" border=\"0\" data-original-height=\"751\" data-original-width=\"1330\" \/><\/a><\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\">In this tutorial, we would cover the following topics<\/div>\n<ol style=\"color: #555555;\">\n<li><a href=\"#t1\">Review of Tutorials 2 and 3<\/a><\/li>\n<li><a href=\"#t2\">About REST Clients<\/a><\/li>\n<li><a href=\"#t3\">Important Concepts of REST Client<\/a><\/li>\n<li><a href=\"#t4\">Test the POST Request<\/a><\/li>\n<li><a href=\"#t5\">Test the PUT Request<\/a><\/li>\n<li><a href=\"#t6\">Test the DELETE Request<\/a><\/li>\n<li><a href=\"#t7\">Next Steps &#8211; Using Data<\/a><\/li>\n<\/ol>\n<div style=\"color: #555555; text-align: center;\"><b><span style=\"color: green;\">If you have any difficulty following this tutorial, explain in the comment box below and I would give you the needed support<\/span>\ud83d\udc47\ud83d\udc47\ud83d\udc47\ud83d\udc47<\/b><\/div>\n<div style=\"color: #555555;\"><\/div>\n<p>&nbsp;<\/p>\n<div style=\"color: #555555;\"><\/div>\n<h3 style=\"color: #555555;\"><b id=\"t1\">1. Review of Tutorial 3<\/b><\/h3>\n<hr style=\"color: #555555;\" \/>\n<div style=\"color: #555555;\">In <a href=\"http:\/\/kindsonthegenius.blogspot.com\/2018\/03\/restful-web-services-tutorial-3.html\" target=\"_blank\" rel=\"noopener noreferrer\">Tutorial 3<\/a>, we successfully creates all the methods for the CRUD operations (GET, POST, PUT and DELETE). Meanwhile CRUD means Create, Read, Update and Delete.<\/div>\n<div style=\"color: #555555;\">You could go to Tutorial 3 if you have not done so because this lesson follows from Tutorial 3.<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\"><\/div>\n<h3 style=\"color: #555555;\"><b id=\"t2\">2. About REST Clients<\/b><\/h3>\n<hr style=\"color: #555555;\" \/>\n<div style=\"color: #555555;\">A REST Client allows you to test RESTful APIs by providing a way of makings a request to the API and specifying neccessary criteria needed to conform to the RESTful architecture. These features provided by a REST client is not readily available in a normal browser application. Two important<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\">REST Clients, which I use and are free are:<\/div>\n<ul style=\"color: #555555;\">\n<li>Postman REST Client<\/li>\n<li>Advanced REST Client<\/li>\n<\/ul>\n<div style=\"color: #555555;\">In this tutorial, we would use Advanced REST Client(ARC)<\/div>\n<div style=\"color: #555555;\"><\/div>\n<h3 style=\"color: #555555;\"><b id=\"t3\">3. Important Features of REST Clients<\/b><\/h3>\n<hr style=\"color: #555555;\" \/>\n<div style=\"color: #555555;\">Remember that to do a GET request, we simply specify the Request URL and select the GET Method. But in this case, we need to do a POST request which requires specifying additional attributes.<\/div>\n<div style=\"color: #555555;\">These are:<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\"><i>1. The Request Body<\/i><\/div>\n<div style=\"color: #555555;\">This is the body of the request which contains the data to be used to create a new resource(in our case, a new Employee).<\/div>\n<div style=\"color: #555555;\">The Request Body shows up when you select POST as the method in the methods list. It apears as a tab between Headers and Variables.<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\"><i>2. Body Content Type<\/i><\/div>\n<div style=\"color: #555555;\">This specifies the type of format of the data you want to pass accross in the body of the request<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\"><i>3.Request-Header<\/i><\/div>\n<div style=\"color: #555555;\">The Header (or HTTP Request Header) allows the client to pass additional information along with the request to the API.<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"clear: both; color: #555555; text-align: center;\"><\/div>\n<div style=\"clear: both; color: #555555; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/4.bp.blogspot.com\/-jhEIoAA1_Cw\/WrV0c-nfTYI\/AAAAAAAABgQ\/-wQSYAbre0g6l2iINZ49e7JX-IhMYChpgCLcBGAs\/s1600\/Tutorial%2B4%2BFigure%2B1%2B-%2BRequest%2BBody.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/4.bp.blogspot.com\/-jhEIoAA1_Cw\/WrV0c-nfTYI\/AAAAAAAABgQ\/-wQSYAbre0g6l2iINZ49e7JX-IhMYChpgCLcBGAs\/s640\/Tutorial%2B4%2BFigure%2B1%2B-%2BRequest%2BBody.jpg\" width=\"640\" height=\"444\" border=\"0\" data-original-height=\"765\" data-original-width=\"1095\" \/><\/a><\/div>\n<div style=\"clear: both; color: #555555; text-align: center;\">Figure 1: POST Request Body<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\"><\/div>\n<h3 style=\"color: #555555;\"><b id=\"t4\">4. Test the POST Request<\/b><\/h3>\n<hr style=\"color: #555555;\" \/>\n<div style=\"color: #555555;\">To carry out this task, be sure that you have completed <a href=\"http:\/\/kindsonthegenius.blogspot.com\/2018\/03\/restful-web-services-tutorial-3.html\" target=\"_blank\" rel=\"noopener noreferrer\">Tutorial 3<\/a>. Follow the\u00a0 steps below.<\/div>\n<div style=\"color: #555555;\"><b>Step 1<\/b>: Open the Employee application we created in <a href=\"http:\/\/kindsonthegenius.blogspot.com\/2018\/03\/restful-web-services-tutorial-3.html\" target=\"_blank\" rel=\"noopener noreferrer\">Tutorial 3<\/a><\/div>\n<div style=\"color: #555555;\"><b>Step 2:<\/b> Run it by pressing F5<\/div>\n<div style=\"color: #555555;\"><b>Step 3<\/b>: Make sure\u00a0 that the browser window opens up<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\"><b>Step 4<\/b>: Lunch Advanced Rest Client (you can launch by entering this link in Chrome <a href=\"https:\/\/chrome.google.com\/webstore\/detail\/advanced-rest-client\/hgmloofddffdnphfgcellkdfbfbjeloo\">https:\/\/chrome.google.com\/webstore\/detail\/advanced-rest-client\/hgmloofddffdnphfgcellkdfbfbjeloo<\/a> because the Advanced REST Client is a Chrome extension)<\/div>\n<div style=\"color: #555555;\"><b>Step 5<\/b>: Select POST from the list of methods<\/div>\n<div style=\"color: #555555;\"><b>Step 6:<\/b> Enter this POST Request URL, which is :<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555; text-align: center;\"><span style=\"color: blue;\">http:\/\/localhost:<span style=\"color: red;\">24675<\/span>\/api\/Employee\/AddEmployee<\/span><\/div>\n<div style=\"color: #555555; text-align: center;\"><\/div>\n<div style=\"color: #555555;\">Also make sure you use the correct port number which you can get from your browser<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\"><b>Step 7<\/b>: Now enter the body of the request to create a new Employee. I have created it below, but you can change to any values you wish<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\"><!-- HTML generated using hilite.me --><\/div>\n<div style=\"background: #ffffff; border: solid gray; color: #555555; overflow: auto; padding: 0.2em 0.6em; width: auto;\">\n<pre style=\"line-height: 125%; margin: 0;\"> {\r\n<span style=\"color: #007700;\">\"EmployeeId\"<\/span>: <span style=\"color: #0000dd; font-weight: bold;\">5<\/span>,\r\n<span style=\"color: #007700;\">\"Name\"<\/span>: <span style=\"background-color: #fff0f0;\">\"Kindson\"<\/span>,\r\n<span style=\"color: #007700;\">\"City\"<\/span>: <span style=\"background-color: #fff0f0;\">\"Akokwa\"<\/span>\r\n}<\/pre>\n<\/div>\n<div style=\"color: #555555;\">Listing 1: Request Body of POST Request<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\"><b>Step 8:<\/b> Change the Body content type to application\/json<\/div>\n<div style=\"color: #555555;\"><b>Step 9:<\/b> Click on the Header tab and Click on Insert headers Set. A default headers set is displayed<\/div>\n<div style=\"color: #555555;\"><b>Step 10:<\/b> Click on USE THIS SET under it. The screen is shown in Figure 2<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"clear: both; color: #555555; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/4.bp.blogspot.com\/-LXxPUJmMwrA\/WrWCyzHyXAI\/AAAAAAAABgg\/odODwStSmfwIdQiaq-55n5vk_X-fXnEGACLcBGAs\/s1600\/Tutorial%2B4%2BFigure%2B1%2B-%2BInsert%2BHeaders%2BSet.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/4.bp.blogspot.com\/-LXxPUJmMwrA\/WrWCyzHyXAI\/AAAAAAAABgg\/odODwStSmfwIdQiaq-55n5vk_X-fXnEGACLcBGAs\/s640\/Tutorial%2B4%2BFigure%2B1%2B-%2BInsert%2BHeaders%2BSet.jpg\" width=\"640\" height=\"433\" border=\"0\" data-original-height=\"771\" data-original-width=\"1136\" \/><\/a><\/div>\n<div style=\"clear: both; color: #555555; text-align: center;\">Figure 2: Inserting Headers Set<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\">At this point, you are now ready to send the POST request<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\"><b>Step 11<\/b>: Click on the SEND button<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\">If you have followed the steps correctly, you should have a response code:<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555; text-align: center;\"><span style=\"color: #274e13;\"><b>201 Created<\/b><\/span><\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\">If you don&#8217;t have this result, let me know by leaving a comment in the comment box below.<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\"><\/div>\n<p>&nbsp;<\/p>\n<h3 style=\"color: #555555;\"><b id=\"t5\">5. Test the PUT Request<\/b><\/h3>\n<hr style=\"color: #555555;\" \/>\n<div style=\"color: #555555;\">The PUT request is used to edit an existing record. What normally do is to display the record I want to edit, then copy it and use it as the body of the PUT request.<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\">The steps you will follow is similar to the steps for the POST request. I would only outline the few differences:<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\">Step 1: Make a GET Request to the employee of Id = 1<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555; text-align: center;\"><span style=\"color: blue;\">http:\/\/localhost:<span style=\"color: red;\">24675<\/span>\/api\/Employee\/Employees\/1<\/span><\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\"><b>Step 2<\/b>: Highlight an copy the record returned by the request<\/div>\n<div style=\"color: #555555;\"><b>Step 3<\/b>: Select PUT from the methods list instead of POST<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\">For the PUT request, use the URL<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555; text-align: center;\"><span style=\"color: blue;\">http:\/\/localhost:<span style=\"color: red;\">24675<\/span>\/api\/Employee\/AddEmployee\/1<\/span><\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\">assuming we want to edit the employee record with Id of 1<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\"><b>Step 4: <\/b>Paste the request body without the Id<\/div>\n<div style=\"color: #555555;\"><b>Step 5:<\/b> Make the needed changes in the record in the request body.<\/div>\n<div style=\"color: #555555;\"><b>Step 6:<\/b> Click on SEND to complete the request<\/div>\n<div style=\"color: #555555;\"><\/div>\n<h3 style=\"color: #555555;\"><b id=\"t6\">6. Test the DELETE Request<\/b><\/h3>\n<hr style=\"color: #555555;\" \/>\n<div style=\"color: #555555;\">For the DELETE request, take note of the following points as it is very similar to the PUT request but without a request body.<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\"><b>Step 1:<\/b> Select DELETE in the methods list<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\">Don&#8217;t specity anything in the Request Body (to delete the entire record)<\/div>\n<div style=\"color: #555555;\"><b>Step 2:<\/b> Enter the DELETE request URL is given by<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555; text-align: center;\"><span style=\"color: blue;\">http:\/\/localhost:<span style=\"color: red;\">24675<\/span>\/api\/Employee\/AddEmployee\/2<\/span><\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\">in case you want to delete the employee record with Id of 2<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\"><b>Step 3: <\/b>Click on SEND<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\"><span style=\"color: red;\"><b>Quiz<\/b>: What response did you get for the DELETE request?<\/span><\/div>\n<div style=\"color: #555555;\">Leave your answer in the comment box below<\/div>\n<div style=\"color: #555555;\"><\/div>\n<p><span style=\"color: #274e13;\"><b>Any problem:<\/b> If you have any difficulty following this tutorial, explain in the comment box below and I would give you the needed support.<\/span><\/p>\n<div style=\"color: #555555;\"><\/div>\n<h3 style=\"color: #555555;\"><b id=\"t7\">7. Next Steps &#8211; Using Data<\/b><\/h3>\n<hr style=\"color: #555555;\" \/>\n<div style=\"color: #555555;\">You can observe that the changes we make through the REST requests are not saved back to anywhere. This is because we have not implemented any functionality to store our data.<\/div>\n<div style=\"color: #555555;\">The current data we use are hard-coded into the the controller file. In the real production application, you would never have to do anything like this.<\/div>\n<div style=\"color: #555555;\">Therefore in the next tutorial, <a href=\"https:\/\/kindsonthegenius.com\/blog\/restful-web-services-tutorial-5-create-employee-database-in-ms-sql-server\/\" target=\"_blank\" rel=\"noopener noreferrer\">Tutorial 5<\/a>, we would set up out application to work with MSSQL database.<\/div>\n<div style=\"color: #555555;\">Then in <a href=\"https:\/\/kindsonthegenius.com\/blog\/restful-web-services-tutorial-6-how-to-create-an-entity-framework-class-diagram-in-visual-studio\/\" target=\"_blank\" rel=\"noopener noreferrer\">Tutorial 6<\/a>, we would generate the equivalent class diagram in Visual Studio<\/div>\n<div style=\"color: #555555;\"><\/div>\n<div style=\"color: #555555;\">For now I would like to thank you for the time you spend learning!<\/div>\n<div style=\"color: #555555;\"><\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Good to see you again! It is good to know that you have come this far. Thumbs up to you! \ud83d\udc4d\ud83d\udc4d\ud83d\udc4d\ud83d\udc4d In this tutorial, we &hellip; <\/p>\n","protected":false},"author":1,"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\/121"}],"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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=121"}],"version-history":[{"count":6,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/121\/revisions"}],"predecessor-version":[{"id":1761,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/121\/revisions\/1761"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=121"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}