Postman collection to send coronavirus stats on slack

栏目: IT技术 · 发布时间: 4年前

内容简介: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

Postman collection to send coronavirus stats on slack

www.postman.com

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.

Postman collection to send coronavirus stats on slack

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));

Postman collection to send coronavirus stats on slack

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 find Monitor collection option. Steps are self explanatory and options are there for monitor to run at different intervals(Weekly, hourly or minutes).

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

代码之美

代码之美

Grey Wilson / 聂雪军 / 机械工业出版社 / 2008年09月 / 99.00元

《代码之美》介绍了人类在一个奋斗领域中的创造性和灵活性:计算机系统的开发领域。在每章中的漂亮代码都是来自独特解决方案的发现,而这种发现是来源于作者超越既定边界的远见卓识,并且识别出被多数人忽视的需求以及找出令人叹为观止的问题解决方案。 《代码之美》33章,有38位作者,每位作者贡献一章。每位作者都将自己心目中对于“美丽的代码”的认识浓缩在一章当中,张力十足。38位大牛,每个人对代码之美都有自......一起来看看 《代码之美》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

SHA 加密
SHA 加密

SHA 加密工具