Postman collection to send coronavirus stats on slack

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

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

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

查看所有标签

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

微机原理与接口技术

微机原理与接口技术

李文英、李勤、刘星、宋蕴新 / 清华大学出版社 / 2001-9 / 26.00元

《高等院校计算机应用技术规划教材•应用型教材系列•微机原理与接口技术》是“高职高专计算机系列教材”之一。全书包括微机原理、汇编语言、接口技术三部分内容。微机原理部分讲述了80x86的内部结构及工作原理、半导体存储器及其系统、微型机总线结构等。汇编语言部分讲述了指令系统、编程技巧。接口技术部分讲述了中断系统、中断控制器、并行接口、串行接口、DMA控制器、定时器,以及A/D、D/A转换器等常用芯片的硬......一起来看看 《微机原理与接口技术》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

SHA 加密
SHA 加密

SHA 加密工具

html转js在线工具
html转js在线工具

html转js在线工具