{"id":8646,"date":"2013-02-28T08:15:11","date_gmt":"2013-02-28T08:15:11","guid":{"rendered":"https:\/\/blog.jetbrains.com\/webide\/?p=5379"},"modified":"2013-04-11T08:40:11","modified_gmt":"2013-04-11T08:40:11","slug":"using-the-rest-client-within-phpstorm","status":"publish","type":"webide","link":"https:\/\/blog.jetbrains.com\/fr\/webide\/2013\/02\/using-the-rest-client-within-phpstorm","title":{"rendered":"Using the REST Client within PhpStorm and WebStorm"},"content":{"rendered":"<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2013\/02\/webide-00-intro.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignleft size-full wp-image-5382\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2013\/02\/webide-00-intro.png\" alt=\"\" width=\"263\" height=\"146\" \/><\/a>When building REST-based web APIs, it\u2019s worth having a tool available to invoke them over HTTP. The current versions of <a href=\"http:\/\/www.jetbrains.com\/webstorm\/\" target=\"_blank\" rel=\"noopener\">WebStorm 6<\/a>, <a href=\"http:\/\/www.jetbrains.com\/phpstorm\/\" target=\"_blank\" rel=\"noopener\">PhpStorm 6<\/a>, <a href=\"http:\/\/www.jetbrains.com\/ruby\/\" target=\"_blank\" rel=\"noopener\">RubyMine 5.4<\/a> and <a href=\"http:\/\/www.jetbrains.com\/pycharm\/\" target=\"_blank\" rel=\"noopener\">PyCharm<\/a> contain a bundled REST Client plugin which allows us to do just that.<\/p>\n<p>In this blog post, we\u2019ll have a quick look at the built-in features of the REST Client and on how to use them.<!--more--><\/p>\n<p>In this post, we\u2019ll be using PhpStorm as our IDE, invoking an API built using the\u00a0<a href=\"http:\/\/silex.sensiolabs.org\/\" target=\"_blank\" rel=\"noopener\">Silex<\/a> framework which is similar to frameworks like\u00a0<a href=\"http:\/\/www.sinatrarb.com\/\" target=\"_blank\" rel=\"noopener\">Sinatra<\/a> and\u00a0<a href=\"http:\/\/www.nancyfx.org\/\" target=\"_blank\" rel=\"noopener\">Nancy<\/a>. The API we\u2019ll be testing using the REST Client plugin is fairly straightforward: it exposes an array of users through a REST endpoint. The <em>\/users<\/em> endpoint returns the entire array of users. The\u00a0<em>\/users\/:id<\/em> endpoint returns a specific user when issuing a GET request and writes a user to the array when issuing a PUT request. The source code for this API is available as a\u00a0<a href=\"https:\/\/gist.github.com\/4654187\" target=\"_blank\" rel=\"noopener\">GitHub Gist<\/a>:<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2013\/02\/webide-03-api1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-5383\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2013\/02\/webide-03-api1.png\" alt=\"\" width=\"653\" height=\"609\" \/><\/a><\/p>\n<p>The REST Client can be found under\u00a0<em>Tools | Test RESTful Web Service<\/em>. A new tab will be opened which gives us the possibility to craft an HTTP request which will be invoked against our API. We can specify the HTTP method to be used, the host where our API is located, and the path to be invoked. Other than that, we can add header data as well as query string parameters or a request body to be sent to the API.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2013\/02\/webide-04-client1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-5720\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2013\/02\/webide-04-client1.png\" alt=\"\" width=\"919\" height=\"423\" \/><\/a><\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2013\/02\/webide-04-client.png\"><\/a><\/p>\n<p>Upon invoking the request by clicking the green\u00a0Run\u00a0button, the REST Client connects to our API and gathers the response data. We can easily inspect the response body as well as the response headers, each available through their own result tab.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2013\/02\/webide-05-response1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-5721\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2013\/02\/webide-05-response1.png\" alt=\"\" width=\"919\" height=\"423\" \/><\/a><\/p>\n<p>To create a user in our API, invoke a PUT request providing JSON data in the request body. We can provide the request body by entering the text or by selecting a file to upload as the body.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2013\/02\/webide-06-json-request1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-5722\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2013\/02\/webide-06-json-request1.png\" alt=\"\" width=\"919\" height=\"423\" \/><\/a><\/p>\n<p>Download\u00a0<a href=\"http:\/\/www.jetbrains.com\/pycharm\/\" target=\"_blank\" rel=\"noopener\">PyCharm<\/a>, <a href=\"http:\/\/www.jetbrains.com\/webstorm\/nextversion\/index.html\" target=\"_blank\" rel=\"noopener\">WebStorm 6 Preview<\/a>, or the\u00a0<a href=\"http:\/\/confluence.jetbrains.com\/display\/WI\/Web+IDE+EAP\" target=\"_blank\" rel=\"noopener\">latest PhpStorm 6 EAP build<\/a> and let us know what you think!<\/p>\n<p><em>Develop with pleasure!<\/em><br \/>\n<em>\u2013 JetBrains Web IDE Team<\/em><\/p>\n","protected":false},"author":118,"featured_media":0,"comment_status":"open","ping_status":"open","template":"","categories":[808],"tags":[779,743,45,153,202],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/webide\/8646"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/webide"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/types\/webide"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/users\/118"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/comments?post=8646"}],"version-history":[{"count":0,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/webide\/8646\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/media?parent=8646"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/categories?post=8646"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/tags?post=8646"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/cross-post-tag?post=8646"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}