内容简介:Though this is not a very optimum time for making a job switch , Last week I joinedThere is an awesome onboarding process that everyone goes through whenever he/she joins the company, as a part of which you are required to make a collection that aims to so
Though this is not a very optimum time for making a job switch , Last week I joined Postman as Software Engineer .
There is an awesome onboarding process that everyone goes through whenever he/she joins the company, as a part of which you are required to make a collection that aims to solve a basic real-world problem. The fact that this is awesome because I feel as an employee it is necessary to know the capabilities of the product that the company owns.
I have used postman before for testing end-points but there is lot more to explore than just that. In this article I have tried to demonstrate how collections and monitors can be used to solve a basic real-world problem , spoon-feeding is a bad practice when it comes to web-development so little effort would be required from your end :wink:.
Collections, as the name says, are a collection of related endpoints. It is like a folder that can be used to group together similar requests and they can be shared as well. Instead of running individual requests we can run collections as well, which will basically run all the requests in that collection.
Monitors can be setup for tracking the performance of API over regular intervals. Adding a monitor for a collection will run the entire collection at a regular interval provided during the setup.
What I did?
https://quickchart.io/
How to do that?
- Find a public api that is Free and create a new collection on Postman app.
Rapid apis has a lot of free apis available. I used https://rapidapi.com/api-sports/api/covid-193 for getting the statistics of Covid-19 cases of a particular country. End-points can be tested on the website itself. Generate an api-key by logging in.
Go to collections tab on postman app and create a new collection. Add a request to get data for a particular country ( Request endpoint ) and save the response received in environment variables , don’t forget to add request headers and api-key. -
Generate chart using chart.io API
Add another request to collection using one of the apis provided by quickchart.io .This will return the generated graph in image format.
In the pre-request script tab fetch the data received in 1st request from the environment variable and format it in a way required to generate a chart. I have used bar chart format. We need the encoded chart data in our next request so save that in one of the environment variable. Use the same variable in the request URL and everything goes well you will be able to see the chart image in response.
- Setup Slack for sending message using Webhooks
A Slack app will be required to send message , create one if needed. Webhooks are one of the easiest ways of posting a message on slack.
Reference the above link to create a slack app in your slack workspace and enable Incoming Webhook URL, which will be used to post message on slack you. It will requires a channel to post to as an app in that you can select your own id so that message will be sent to yourself.
Add one more request to the collection with webhooks url obtained from slack. We need to format the data again in a format supported by slack.
Add the following code in pre-request tab of this new request. Make sure that the required environment variables are present, in this case its encoded_chart
and CHART_URL
.
const encodedChart = pm.environment.get("encoded_chart");const chart_url = pm.environment.get("CHART_URL");// chart payload for slack const chart_payload = [{ type: "image", title: { type: "plain_text", text: "bar chart" }, block_id: "quickchart-image", image_url: `${chart_url}?bkg=white&c=${encodedChart}`, alt_text: "Chart showing latest data" }]; pm.environment.set("chart_payload", JSON.stringify(chart_payload));
Add the chart payload saved during pre-request script chart_payload
to the request body as shown in image. Go ahead and send the request and I hope you get a slack notification.
-
Adding a Monitor to the collection
This is easy just click on 3-dots on collections tab in Postman app and findMonitor collection
option. Steps are self explanatory and options are there for monitor to run at different intervals(Weekly, hourly or minutes).
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。