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

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

查看所有标签

猜你喜欢:

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

组成论

组成论

张学文 / 中国科学技术大学出版社 / 2003-12 / 35.00元

很多事物中都存在组成(成分、构成)问题。作者创立的组成论为此提供统一的认识模型、分析工具、计算方法和原理。它通过广义集合、分布函数和复杂程度三个概念分析事物组成,并揭示了有随机性的事物都遵守最复杂原理。组成论与系统科学、复杂性研究、信息论和热力学第二定律关系密切。本书介绍了它在自然和社会科学中的许多应用,还提出了信息不可增殖、不同形态的复杂程度的互相转化(复杂度定律)等重要论点。自然科学、社会科学......一起来看看 《组成论》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

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

html转js在线工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具