Postman or CLI. My Choice for the task in hand

·

2 min read

I was given a Postman collection export file at work yesterday. Looking over this JSON file I thought, Do I really need to import that into Postman?
Could I make some better for this task?

For repetitive GET requests without worrying about human error creeping in, yes Postman is fine. I don't use Postman enough to dig deep with it.

The requests in the file were designed to interrogate a server for information related to a specific object, an object that could change with every use of the request and the collection would never run all of those requests at the same time.

So for a few hours after work, I decided it was going to be an evening writing a little bit of Python and build a command-line tool.

I am a big fan of working modular, as I like to be able to write variations on the same code and it saves time not to have to pull code apart or worse, copy and paste large chunks of code into other apps.

For this project, I decided three modules would be a good starting point.

main
This is the app initialisation.
Clears the console with os.system and then prints to console a header for the app and a list of options with an input statement. This initial list requires the users to state what information they currently have of the object they are looking to interrogate further. Once the user has stated what information they have the appropriate function from choice_functions is selected.

choice_functions
Each function clears the console with os.system and then prints to console a header for the choice, and a selection of possible GET requests. Using another input statement to gather their choice. With the choice made, the known information is requested from the user. This information is then passed to the appropriate function in request_functions for the construction of the GEt request and actioned.

request_functions
This module holds the functions to construct each of the API GET requests. Currently, the replies are just sent to the console.

That's was my first evening sorted, there is still plenty to do.
Save replies to file
File formatting
Discard irrelevant information
Reuse modules to allow the import of lists or dicts to pull multiple requests
Maybe even design a front-end GUI for this (Maybe!)