{"id":3159,"date":"2019-03-06T22:15:21","date_gmt":"2019-03-06T22:15:21","guid":{"rendered":"https:\/\/blog.paranoidprofessor.com\/?p=3159"},"modified":"2019-03-06T22:15:21","modified_gmt":"2019-03-06T22:15:21","slug":"stupid-postman-tricks","status":"publish","type":"post","link":"https:\/\/blog.paranoidprofessor.com\/index.php\/2019\/03\/06\/stupid-postman-tricks\/","title":{"rendered":"Stupid postman tricks"},"content":{"rendered":"<p>First the technology. RESTful calls are actually pretty cool. It is neat to simply send off a GET or POST message and extract or update the server with vital information. I am not going to write up a long article, well at this point anyway, describing RESTful calls.<\/p>\n<p>Due to the flexibility and function of these calls there are a lot of tools and systems that make use of them.\u00a0One such tool is Postman. This is a perfect tool for testing your RESTful calls on your servers. This might be during testing or it could be during development.<\/p>\n<h2>Performance<\/h2>\n<p>I was tasked with setting up some performance tests in another tool and my specification was a Postman script. You cannot really ask for a better specification than something that almost works like a finished program.<\/p>\n<p>The only problem was that I had to run a few different steps and one of the steps required value from the previous step. This is actually almost trivial in Postman but the problem was I needed both the name and the value.\u00a0 The source code that I had needed parse looked like this.<\/p>\n<pre class=\"yiv4002654693MsoNormal\">&lt;input type=\"hidden\" name=\"xsrf_CppTDEqKjryFYA9agpaloQ\" value=\"LugLnMWKGWyiZD64jwys4g\"&gt;<\/pre>\n<p>I need to pass back a variable called\u00a0<strong>xsrf_CppTDEqKjryFYA9agpaloQ<\/strong> with the value\u00a0<strong>LugLnMWKGWyiZD64jwys4g<\/strong> in the next postman step.<\/p>\n<p>The good news is that postman uses java script as its scripting language.\u00a0 This allows you to do plenty of interesting things when testing response values.\u00a0 In my case I decided to use java script to parse the login page that is retrieved and then essentially an inelegant\u00a0 search through the text for these values.<\/p>\n<p><br \/>\nmysplits=data.split(&#8221; &#8220;);<\/p>\n<p>searchname=&#8217;name=&#8221;xsrf&#8217;;<br \/>\nvar idx;<br \/>\nvar valueidx=-1;<br \/>\nvar cnt=mysplits.length;<\/p>\n<p>for (idx=0; idx &lt; cnt; idx++)<br \/>\n{<br \/>\n\/\/console.log(mysplits[idx]);<br \/>\nvar search = mysplits[idx].substr(0,10);<br \/>\nif (search == searchname)<br \/>\n{<br \/>\nvar pieces=mysplits[idx].split(&#8220;\\&#8221;&#8221;);<br \/>\nconsole.log(&#8220;found&#8221;);<br \/>\nconsole.log(search);<br \/>\nconsole.log(pieces[1]);<br \/>\nvalueidx=idx+1;<br \/>\n}<\/p>\n<p>if (valueidx == idx)<br \/>\n{<br \/>\nvar pieces=mysplits[idx].split(&#8220;\\&#8221;&#8221;);<br \/>\nconsole.log(pieces[1]);<br \/>\n}<br \/>\n}<br \/>\n<\/p>\n<p>This isn&#8217;t the type of code you would want to use for any production solutions but it is a fun little hack to assist during development.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>First the technology. RESTful calls are actually pretty cool. It is neat to simply send off a GET or POST message and extract or update the server with vital information. I am not going to write up a long article, &hellip; <a href=\"https:\/\/blog.paranoidprofessor.com\/index.php\/2019\/03\/06\/stupid-postman-tricks\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[20],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/3159"}],"collection":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/comments?post=3159"}],"version-history":[{"count":1,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/3159\/revisions"}],"predecessor-version":[{"id":3160,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/3159\/revisions\/3160"}],"wp:attachment":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/media?parent=3159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/categories?post=3159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/tags?post=3159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}