paint-brush
Test Your APIs in an Easy Way By Using Python Module PyHTTPTestby@slaily
1,010 reads
1,010 reads

Test Your APIs in an Easy Way By Using Python Module PyHTTPTest

by IliyanOctober 28th, 2019
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Pyhttptest is a command-line tool for HTTP tests over Web server, elegantly solves the problem in simple three steps. Describe your HTTP Requests test cases against your service in a simplest and widely used format. At the moment only "GET" and "POST" are supported. The properties, which you can pass to a file are: name of your test case e.g "Get all users", verb, endpoint, host, query string, payload and query string.

Company Mentioned

Mention Thumbnail
featured image - Test Your APIs in an Easy Way By Using Python Module PyHTTPTest
Iliyan HackerNoon profile picture

I've struggled and spent a lot of hours writing manual Python scripts to be able to test a product involving many microservices. All of them following the REST conventions. Overwhelmed with too many scripts, each one test different endpoints, how they respond also what they respond, I've decided to create a Python package to easily do this, without needing to create a manual Python script, import libraries to send an HTTP Request, copy and paste code from other scripts to test fast the new endpoints, etc.

Happy to announce pyhttptest!

My first contribution to the Python community, released in PyPI.

pyhttptest - A command-line tool for HTTP tests over Web server, elegantly solves the problem in simple three steps.

1. Install the package

pip install pyhttptest

2. Describe your HTTP Requests test cases against your service in a simplest and widely used format JSON within a file.

1. To send an HTTP GET Request:

Create a JSON file, for example, data/GET_USERS.json

{
  "name": "TEST: Github Page",
  "verb": "GET",
  "endpoint": "/",
  "host": "https://github.com",
  "headers": {
    "Accept-Language": "en-US"
  }
}

2. To send an HTTP POST Request:

Create a JSON file, for example, data/POST_BIN.json

{
  "name": "TEST: Create an HTML bin",
  "verb": "POST",
  "endpoint": "post",
  "host": "https://httpbin.org",
  "payload": {
    "content": "Hello, world!"
  }
}

The properties, which you can pass to a

.json
file are:

  • name - The name of your test case e.g "Get all users".
  • verb - An HTTP Method e.g "GET", "POST". AT THE MOMENT ONLY "GET" and "POST" ARE SUPPORTED.
  • endpoint - The resource you want to invoke on your server e.g "/users".
  • host - Your server identification, could be e.g "http://localhost:8008," "https://github.com" etc.
  • headers - An HTTP Headers. All HTTP header fields are supported.
  • query_string - Pass query string parameters in the URL after question mark e.g http://example.com/test?name=pyhttptest
  • payload - The data.

NOTE: There are required and optional properties for .json

Required:

  • name
  • verb
  • endpoint
  • host

Optional:

  • headers
  • payload
  • query_string
  • 3. Run command and gain report

    pyhttptest execute data/GET_USERS.json 

    That's it!

    Currently, the package is in the Beta version, it may contain bugs, not user-friendly messages, etc.

    I want to gather feedback from anyone of you, it doesn't matter if it is positive or negative.

    It'll help me to prepare the package to be better for the official release version.

    Waiting for your feedback and list of features for implementation or features to remove to make your work easier!

    Thanks for your attention and feedback! I've appreciated it!