Introduction to Dynamic CLI in Python
In this article, we will see an introduction to Dynamic CLI in Python.
What is Dynamic CLI?
A Modern, user-friendly command-line HTTP client for API testing, It helps a programmer to code more efficiently by increasing one’s productivity and by reducing the time and effort required to perform tasks of searching for solutions and making API requests. So without wasting any further time let’s get right into it. Also using postman and other software for API testing are good but can be difficult for a beginner, dynamic-cli also provides the functionality of API testing where you can simply make API requests from your terminal.
Installation Using PIP
Use the following command
pip3 install dynamic-cli
Installation Using Virtual Environment
You can use this method to avoid possible issues with dependencies or permissions. This is recommended method
Install virtualenv
pip3 install virtualenv
Create a dynamic-cli virtualenv and install dynamic-cli:
mkvirtualenv dynamic-cli
pip3 install dynamic-cli
If you want to activate the dynamic-cli virtualenv again later, run:
workon dynamic-cli
To deactivate the dynamic-cli virtualenv, run:
deactivate
Searching For Error
Now that dynamic CLI is installed correctly we can move forward and use it. Dynamic CLI offers different command-line arguments for different tasks such as for searching for something we use the command:
dynamic -s
Step 1. After pressing enter you will be asked to enter an error/question to search
Enter Question
Step 2. After that you will be asked to enter tags for a better search this is optional.
Optional Tags
Step 3. Now there will be multiple results to questions you can toggle between each one and get the answer.
Results
Step 4. If you want to open that question in the browser you can press ‘enter’.
Opened Browser
Step 5. If you wanna save questions to the playbook for later access you can press ‘p’.
Question saved in playbook
Step 6. If you want to quit you can press ‘ESC’ or ‘q’.
Accessing Playbook
You started using dynamic CLI found multiple answers and saved them in the playbook but if you want to retrieve them later to do this you need to access a playbook that is stored in your local storage. To do that you can use the following command.
dynamic -p
This will show all the questions stored in the playbook
Playbook
API Testing
Moving on to the next use of dynamic cli you can also send requests to an API and receive responses. There are three HTTP methods you can use as of now which are:
Let’s see how to use them one by one, for this tutorial I am going to use reqres.in which is a platform to make sample AJAX requests.
Also once you successfully get a response you can store in your local drive.
GET Method
To perform the GET HTTP method enter the following command to your terminal
dynamic -GET
After you press enter on your terminal it will ask you to enter the URL to make the request after that you will need to enter headers if your request needs headers you can add them then it will get the response and present to you in JSON format after that you will be asked if you want to save results if you press ‘Y’ then enter the file name you want to store your results in and press enter.
GET Method
POST Method
To perform the POST HTTP method enter the following command to your terminal
dynamic -POST
In the POST method we send the payload(data) there are two ways using which you can send data in dynamic-cli. First, you will be asked to enter the URL then you can add headers then you will be asked if you want to send payload data or not if you press ‘Y’ you will be prompted with two choices which are
Sending Payload from terminal
If you choose first then you can send data from the terminal you need to specify data in key:value format just like we specify in the curl request.
After that, you can save the response.
Sending Payload from JSON file
If you choose option two you can send data from the JSON input file. You need to specify the name of the file and you will get the JSON response which you can save.
POST Method
DELETE Method
To perform the DELETE HTTP method enter the following command to your terminal
dynamic -DELETE
Same as other HTTP methods first you will be asked to enter the URL after that headers if the deletion operation is successful you will have the response with HTTP code 204 which represents no content.
DELETE Method
Last Updated :
12 Jul, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...