<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>api Archives - Tech Chronicles</title>
	<atom:link href="http://kostacipo.stream/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>http://kostacipo.stream/tag/api/</link>
	<description>Ramblings of a Tech Dude</description>
	<lastBuildDate>Tue, 24 Dec 2019 13:28:32 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>

<image>
	<url>https://kostacipo.stream/wp-content/uploads/2019/12/cropped-profile-32x32.jpg</url>
	<title>api Archives - Tech Chronicles</title>
	<link>http://kostacipo.stream/tag/api/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Testing REST APIs easily in Python with pyhttptest</title>
		<link>http://kostacipo.stream/testing-rest-apis-easily-in-python-with-pyhttptest/</link>
					<comments>http://kostacipo.stream/testing-rest-apis-easily-in-python-with-pyhttptest/#respond</comments>
		
		<dc:creator><![CDATA[Majordomo]]></dc:creator>
		<pubDate>Tue, 24 Dec 2019 12:31:05 +0000</pubDate>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">http://www.kostacipo.stream/?p=1527</guid>

					<description><![CDATA[<p>&#160; Nowadays every one of us is facing REST APIs by either developing or consuming such a service. Also, we’re in the trendy era of microservices, where we splitting our business logic into small separate services independent from each one. Mostly these services follow RESTful principles and using the JSON format for communication, which became [&#8230;]</p>
<p>The post <a href="http://kostacipo.stream/testing-rest-apis-easily-in-python-with-pyhttptest/">Testing REST APIs easily in Python with pyhttptest</a> appeared first on <a href="http://kostacipo.stream">Tech Chronicles</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>&nbsp;</p>
<div class="paragraph">Nowadays every one of us is facing REST APIs by either developing or consuming such a service. Also, we’re in the trendy era of microservices, where we splitting our business logic into small separate services independent from each one. Mostly these services follow RESTful principles and using the JSON format for communication, which became the most widely used format, because of its simplicity.</p>
</div>
<div class="paragraph"><a href="https://github.com/slaily/pyhttptest"><strong>pyhttptest</strong></a> &#8211; A command-line tool for HTTP tests over RESTful APIs&nbsp;</div>
<div class="paragraph">This tool automate testing in a simple three steps.</p>
</div>
<div class="paragraph"><strong>1. Install the package</strong></div>
<div class="code-container">
<pre><code>pip install pyhttptest</code></pre>
</div>
<div class="paragraph"><strong>2. Describe your HTTP Requests test cases against your API service in a simplest and widely used format JSON within a file.</strong></div>
<h5 class="paragraph"><strong>Single test case definition examples</strong>&nbsp;</h5>
<p>To send an HTTP GET Request:</p>
<p>Create a JSON file, for example, data/test_server_status.json</p>
<div class="code-container">
<pre><code>{
  <span class="hljs-attr">"name"</span>: "TEST: Get server status",
  <span class="hljs-attr">"verb"</span>: "GET",
  <span class="hljs-attr">"endpoint"</span>: "/get",
  <span class="hljs-attr">"host"</span>: "https://httpbin.org",
  <span class="hljs-attr">"headers"</span>: {
    <span class="hljs-attr">"Accept-Language"</span>: "en-US"
  }
}
</code></pre>
</div>
<p>To send an HTTP POST Request:</p>
<p>Create a JSON file, for example, data/test_create_html_bin.json</p>
<div class="code-container">
<pre><code>{
  <span class="hljs-attr">"name"</span>: "TEST: Create an HTML bin",
  <span class="hljs-attr">"verb"</span>: "POST",
  <span class="hljs-attr">"endpoint"</span>: "post",
  <span class="hljs-attr">"host"</span>: "https://httpbin.org",
  <span class="hljs-attr">"payload"</span>: {
    <span class="hljs-attr">"content"</span>: "Hello, world!"
  }
}
</code></pre>
</div>
<div class="paragraph"><strong>Multiple test cases definition example</strong></div>
<ul>
<li>Create a JSON file, for example, data/requests.json</li>
</ul>
<div class="code-container">
<pre><code>[
  {
    <span class="hljs-attr">"name"</span>: "TEST: List all users",
    <span class="hljs-attr">"verb"</span>: "GET",
    <span class="hljs-attr">"endpoint"</span>: "api/v1/users",
    <span class="hljs-attr">"host"</span>: "http://localhost:8085/",
    <span class="hljs-attr">"headers"</span>: {
      <span class="hljs-attr">"Accept-Language"</span>: "en-US"
    },
    <span class="hljs-attr">"query_string"</span>: {
      <span class="hljs-attr">"limit"</span>: 1
    }
  },
  {
    <span class="hljs-attr">"name"</span>: "TEST: Add a new user",
    <span class="hljs-attr">"verb"</span>: "POST",
    <span class="hljs-attr">"endpoint"</span>: "api/v1/users",
    <span class="hljs-attr">"host"</span>: "http://localhost:8085/",
    <span class="hljs-attr">"payload"</span>: {
      <span class="hljs-attr">"username"</span>: "pyhttptest",
      <span class="hljs-attr">"email"</span>: "admin@pyhttptest.com"
    }
  },
  {
    <span class="hljs-attr">"name"</span>: "TEST: Modify an existing user",
    <span class="hljs-attr">"verb"</span>: "PUT",
    <span class="hljs-attr">"endpoint"</span>: "api/v1/users/XeEsscGqweEttXsgY",
    <span class="hljs-attr">"host"</span>: "http://localhost:8085/",
    <span class="hljs-attr">"payload"</span>: {
      <span class="hljs-attr">"username"</span>: "pyhttptest"
    }
  },
  {
    <span class="hljs-attr">"name"</span>: "TEST: Delete an existing user",
    <span class="hljs-attr">"verb"</span>: "DELETE",
    <span class="hljs-attr">"endpoint"</span>: "api/v1/users/XeEsscGqweEttXsgY",
    <span class="hljs-attr">"host"</span>: "http://localhost:8085/"
  }
]
</code></pre>
</div>
<div class="paragraph"><strong>3. Run command and gain report</strong></div>
<div class="code-container">
<pre><code>pyhttptest execute data/test_server_status.json</code></pre>
</div>
<div class="paragraph">The report from the single test case</div>
<div class="image-container"><img decoding="async" src="https://hackernoon.com/photos/yiScHMLD3KMMgF6nwvdcdTcgDdP2-4ha32tw" alt=""></div>
<div class="code-container">
<pre><code>pyhttptest execute data/requests.json</code></pre>
</div>
<div class="paragraph">The report from the multiple test cases</div>
<div class="image-container"><img decoding="async" src="https://hackernoon.com/photos/yiScHMLD3KMMgF6nwvdcdTcgDdP2-hc1r2324k" alt=""></div>
<div class="paragraph">The properties, which you can pass to a json file are:</div>
<ul>
<li>name &#8211; The name of the test case.</li>
<li>verb &#8211; An HTTP Method.</li>
<li>endpoint &#8211; The resource you want to invoke on the server.</li>
<li>host &#8211; Server host address.</li>
<li>headers &#8211; An HTTP Headers. All HTTP header <a href="https://en.wikipedia.org/wiki/List_of_HTTP_header_fields">fields</a> are supported.</li>
<li>query_string &#8211; Query string parameters in the URL after the question mark.</li>
<li>payload &#8211; The data.</li>
</ul>
<div class="paragraph"><strong>Best practices</strong></div>
<div class="paragraph">One question may arise in your mind, how to add, structure and organize the test cases into my existing/new project. Every Python project, which has tests contains in his project directory a folder namely</p>
<pre><code>tests/</code></pre>
<p>From this directory by convention, great frameworks like</p></div>
<div class="paragraph">
<pre><code>unittest</code></pre>
<p>and</p>
<pre><code>pytest</code></pre>
<p>discover and execute defined test cases in Python scripts. To not mess up with these tests and break the conventions, I suggest creating a new directory in your project root directory named</p>
<pre><code>live_tests/</code></pre>
<p>Inside the new directory, you can put all .</p></div>
<div class="paragraph">
<pre><code>json</code></pre>
<p>files with defined test cases for the API. By doing this your tests will be easily distinguished. But it’s really up to you!</p></div>
<p>The post <a href="http://kostacipo.stream/testing-rest-apis-easily-in-python-with-pyhttptest/">Testing REST APIs easily in Python with pyhttptest</a> appeared first on <a href="http://kostacipo.stream">Tech Chronicles</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>http://kostacipo.stream/testing-rest-apis-easily-in-python-with-pyhttptest/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
