{"id":1137,"date":"2014-03-27T04:32:37","date_gmt":"2014-03-27T04:32:37","guid":{"rendered":"http:\/\/www.rezafaisal.net\/?p=1137"},"modified":"2014-04-06T12:57:27","modified_gmt":"2014-04-06T12:57:27","slug":"mengakses-dan-menguji-web-api-dengan-tool-a-simple-test-client-for-asp-net-web-api","status":"publish","type":"post","link":"http:\/\/www.rezafaisal.net\/?p=1137","title":{"rendered":"Mengakses dan Menguji Web API dengan Tool A Simple Test Client for ASP.NET Web API"},"content":{"rendered":"<p>Pada posting sebelumnya <a title=\"http:\/\/www.rezafaisal.net\/?p=1125\" href=\"http:\/\/www.rezafaisal.net\/?p=1125\">http:\/\/www.rezafaisal.net\/?p=1125<\/a> telah di bahas tentang halaman bantuan dimana pada halaman tersebut kita dapat melihat class controller apa saja yang ada pada project dan method-method apa saja yang terdapat pada setiap class.<\/p>\n<p>Tetapi bagi yang ingin mencoba menggunakan fungsi-fungsi tersebut harus tetap melakukan akses langsung masing-masing method pada class controller via url baik yang bisa dilakukan dengan akses web browser atau secara memrograman.\u00a0 Pada posting ini akan dibahas bagaimana mengakses dan menguji method pada class controller Web API dengan bantuan \u201c<a href=\"https:\/\/nuget.org\/packages\/WebApiTestClient\">A Simple Test Client for ASP.NET Web API<\/a>\u201d.\u00a0 Tool ini nantinya akan diintegrasikan dengan halaman bantuan Web API.<\/p>\n<p>Berikut adalah langkah-langkah yang dapat dilakukan :<\/p>\n<p>{<strong><em>Installasi A Simple Test Client for ASP.NET Web API<\/em><\/strong>}<\/p>\n<p>Untuk menambahkan \u201ctool\u201d ini pada project web adalah dengan cara akses fitur Manage NuGet Packages, dengan cara klik kanan pada project yang diinginkan kemudian pilih fitur tersebut.<\/p>\n<p><a href=\"http:\/\/www.rezafaisal.net\/wp-content\/uploads\/2014\/03\/blog16.jpg\"><img loading=\"lazy\" decoding=\"async\" title=\"blog1\" alt=\"blog1\" src=\"http:\/\/www.rezafaisal.net\/wp-content\/uploads\/2014\/03\/blog1_thumb6.jpg\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" border=\"0\" width=\"523\" height=\"346\" \/><\/a><\/p>\n<p>Keyword yang bisa digunakan adalah WebApiTestClient, maka akan didapat daftar seperti di atas, kemudian klik tombol Install.<\/p>\n<p><a href=\"http:\/\/www.rezafaisal.net\/wp-content\/uploads\/2014\/03\/blog25.jpg\"><img loading=\"lazy\" decoding=\"async\" title=\"blog2\" alt=\"blog2\" src=\"http:\/\/www.rezafaisal.net\/wp-content\/uploads\/2014\/03\/blog2_thumb5.jpg\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" border=\"0\" width=\"523\" height=\"346\" \/><\/a><\/p>\n<p>Selajutnya modifikasi file Api.cshtml yang terdapat pada folder Areas\\HelpPage\\Views\\Help.<\/p>\n<div style=\"overflow: auto; cursor: text; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 97.5%; direction: ltr; text-align: left; margin: 20px 0px 10px; line-height: 12pt; max-height: 200px; background-color: #f4f4f4; border: silver 1px solid; padding: 4px;\" id=\"codeSnippetWrapper\">\n<div style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\" id=\"codeSnippet\">\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum1\">   1:<\/span> @using System.Web.Http<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum2\">   2:<\/span> @using ASP.Areas.HelpPage.Models<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum3\">   3:<\/span> @model HelpPageApiModel<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum4\">   4:<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum5\">   5:<\/span> @{<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum6\">   6:<\/span>     var description = Model.ApiDescription;<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum7\">   7:<\/span>     ViewBag.Title = description.HttpMethod.Method + \" \" + description.RelativePath;<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum8\">   8:<\/span> }<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum9\">   9:<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum10\">  10:<\/span> <span style=\"color: #0000ff;\">&lt;<\/span><span style=\"color: #800000;\">link<\/span> <span style=\"color: #ff0000;\">type<\/span><span style=\"color: #0000ff;\">=\"text\/css\"<\/span> <span style=\"color: #ff0000;\">href<\/span><span style=\"color: #0000ff;\">=\"~\/Areas\/HelpPage\/HelpPage.css\"<\/span> <span style=\"color: #ff0000;\">rel<\/span><span style=\"color: #0000ff;\">=\"stylesheet\"<\/span> <span style=\"color: #0000ff;\">\/&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum11\">  11:<\/span> <span style=\"color: #0000ff;\">&lt;<\/span><span style=\"color: #800000;\">div<\/span> <span style=\"color: #ff0000;\">id<\/span><span style=\"color: #0000ff;\">=\"body\"<\/span> <span style=\"color: #ff0000;\">class<\/span><span style=\"color: #0000ff;\">=\"help-page\"<\/span><span style=\"color: #0000ff;\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum12\">  12:<\/span>     <span style=\"color: #0000ff;\">&lt;<\/span><span style=\"color: #800000;\">section<\/span> <span style=\"color: #ff0000;\">class<\/span><span style=\"color: #0000ff;\">=\"featured\"<\/span><span style=\"color: #0000ff;\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum13\">  13:<\/span>         <span style=\"color: #0000ff;\">&lt;<\/span><span style=\"color: #800000;\">div<\/span> <span style=\"color: #ff0000;\">class<\/span><span style=\"color: #0000ff;\">=\"content-wrapper\"<\/span><span style=\"color: #0000ff;\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum14\">  14:<\/span>             <span style=\"color: #0000ff;\">&lt;<\/span><span style=\"color: #800000;\">p<\/span><span style=\"color: #0000ff;\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum15\">  15:<\/span>                 @Html.ActionLink(\"Help Page Home\", \"Index\")<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum16\">  16:<\/span>             <span style=\"color: #0000ff;\">&lt;\/<\/span><span style=\"color: #800000;\">p<\/span><span style=\"color: #0000ff;\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum17\">  17:<\/span>         <span style=\"color: #0000ff;\">&lt;\/<\/span><span style=\"color: #800000;\">div<\/span><span style=\"color: #0000ff;\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum18\">  18:<\/span>     <span style=\"color: #0000ff;\">&lt;\/<\/span><span style=\"color: #800000;\">section<\/span><span style=\"color: #0000ff;\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum19\">  19:<\/span>     <span style=\"color: #0000ff;\">&lt;<\/span><span style=\"color: #800000;\">section<\/span> <span style=\"color: #ff0000;\">class<\/span><span style=\"color: #0000ff;\">=\"content-wrapper main-content clear-fix\"<\/span><span style=\"color: #0000ff;\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum20\">  20:<\/span>         @Html.DisplayForModel()<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum21\">  21:<\/span>     <span style=\"color: #0000ff;\">&lt;\/<\/span><span style=\"color: #800000;\">section<\/span><span style=\"color: #0000ff;\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum22\">  22:<\/span> <span style=\"color: #0000ff;\">&lt;\/<\/span><span style=\"color: #800000;\">div<\/span><span style=\"color: #0000ff;\">&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum23\">  23:<\/span> @Html.DisplayForModel(\"TestClientDialogs\")<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum24\">  24:<\/span> @section Scripts {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum25\">  25:<\/span>     @Html.DisplayForModel(\"TestClientReferences\")<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum26\">  26:<\/span>     <span style=\"color: #0000ff;\">&lt;<\/span><span style=\"color: #800000;\">link<\/span> <span style=\"color: #ff0000;\">type<\/span><span style=\"color: #0000ff;\">=\"text\/css\"<\/span> <span style=\"color: #ff0000;\">href<\/span><span style=\"color: #0000ff;\">=\"~\/Areas\/HelpPage\/HelpPage.css\"<\/span> <span style=\"color: #ff0000;\">rel<\/span><span style=\"color: #0000ff;\">=\"stylesheet\"<\/span> <span style=\"color: #0000ff;\">\/&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span style=\"color: #606060;\" id=\"lnum27\">  27:<\/span> }<\/pre>\n<p><!--CRLF--><\/p>\n<\/div>\n<\/div>\n<p>Dan tambahkan baris ke-23 sampai baris ke-27 ke halaman Api.cshtml tersebut.<\/p>\n<p>{<strong><em>Testing<\/em><\/strong>}<\/p>\n<p>Maka akan dapat dilihat akan terdapat tambahan tombol \u201cTest API\u201d pada pojok kiri bawah pada halaman bantuan ketika kita mengakses bantuan dari suatu method pada class controller.<\/p>\n<p><a href=\"http:\/\/www.rezafaisal.net\/wp-content\/uploads\/2014\/03\/blog33.jpg\"><img loading=\"lazy\" decoding=\"async\" title=\"blog3\" alt=\"blog3\" src=\"http:\/\/www.rezafaisal.net\/wp-content\/uploads\/2014\/03\/blog3_thumb3.jpg\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" border=\"0\" width=\"523\" height=\"333\" \/><\/a><\/p>\n<p>Dan berikut adalah tampilan ketika tombol \u201cTest API\u201d diklik, akan tampil window seperti pada gambar di bawah.<\/p>\n<p><a href=\"http:\/\/www.rezafaisal.net\/wp-content\/uploads\/2014\/03\/blog43.jpg\"><img loading=\"lazy\" decoding=\"async\" title=\"blog4\" alt=\"blog4\" src=\"http:\/\/www.rezafaisal.net\/wp-content\/uploads\/2014\/03\/blog4_thumb3.jpg\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" border=\"0\" width=\"523\" height=\"277\" \/><\/a><\/p>\n<p>Dan berikut adalah hasil yang dapat dilihat ketika tombol Send diklik. Selain hasil output body juga dapat dilihat status dan header dari response method yang sedang kita akses tersebut.<\/p>\n<p><a href=\"http:\/\/www.rezafaisal.net\/wp-content\/uploads\/2014\/03\/blog52.jpg\"><img loading=\"lazy\" decoding=\"async\" title=\"blog5\" alt=\"blog5\" src=\"http:\/\/www.rezafaisal.net\/wp-content\/uploads\/2014\/03\/blog5_thumb3.jpg\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" border=\"0\" width=\"523\" height=\"277\" \/><\/a><\/p>\n<p>Selamat mencoba :)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pada posting sebelumnya http:\/\/www.rezafaisal.net\/?p=1125 telah di bahas tentang halaman bantuan dimana pada halaman tersebut kita dapat melihat class controller apa saja yang ada pada project dan method-method apa saja yang terdapat pada setiap class. Tetapi bagi yang ingin mencoba menggunakan&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1130,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[6],"tags":[68,96,108],"class_list":["post-1137","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-softwaredev","tag-asp-net","tag-vs-2013","tag-web-api"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"http:\/\/www.rezafaisal.net\/wp-content\/uploads\/2014\/03\/blog2_thumb5.jpg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1sNAL-il","_links":{"self":[{"href":"http:\/\/www.rezafaisal.net\/index.php?rest_route=\/wp\/v2\/posts\/1137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.rezafaisal.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.rezafaisal.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.rezafaisal.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.rezafaisal.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1137"}],"version-history":[{"count":2,"href":"http:\/\/www.rezafaisal.net\/index.php?rest_route=\/wp\/v2\/posts\/1137\/revisions"}],"predecessor-version":[{"id":1147,"href":"http:\/\/www.rezafaisal.net\/index.php?rest_route=\/wp\/v2\/posts\/1137\/revisions\/1147"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.rezafaisal.net\/index.php?rest_route=\/wp\/v2\/media\/1130"}],"wp:attachment":[{"href":"http:\/\/www.rezafaisal.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.rezafaisal.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1137"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.rezafaisal.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}