Monitor Your Webhook Workflows with New Incoming Requests for API Tests

综合技术 2016-04-20

API testing and monitoring has traditionally focused solely on outbound requests that simulate what a client of a particular API or endpoint would experience. But APIs are increasingly becoming a two-way conversation, with data flowing into apps asynchronously based on events happening (e.g. GitHub commits, Twilio text messages received, bots receiving requests, etc.). The most popular way this occurs is via a pattern known as webhooks .

Testing a webhooks implementation can be difficult. While you can exercise specific endpoints that consume an event payload (Runscope is great at this), generating test events that mimic real-world conditions is a manual process. What we need is an API testing tool that understands data going out via API calls, but also data coming in via asynchronous callbacks, and the relationship between the two.

Introducing Monitoring and Testing for Webhooks

Today we've added a new feature to our API testing and monitoring lineup that allows you to combine outgoing API calls with incoming callback requests. To understand how this works, let's take a look at a simple example.

Testing Twilio Status Callback URLs

Twilio is an API that allows developers to add communications (voice, text, video) features to their applications. One of the most popular products they offer is their SMS API. When sending SMS, it's really important to know whether or not a message was delivered. The Twilio API offers a " Status Callback URL " that will notify your app of delivery status after you send a message. Delivering a message takes a little bit of time so it's not possible to include a delivery status in the response to the original API call. Instead, you can pass a URL to be notified at asynchronously once the delivery attempt is completed.

To test this scenario, we can create a test that sends an SMS message via an outbound API call, then waits for a callback request containing the delivery status using the new Incoming Request Step type:

Incoming Request Steps can be validated just like the responses of outgoing API calls. In this case, we're checking for a form POST parameter named MessageStatus to make sure the value is correct. You can also check JSON attributes, extract and store values to use in subsequent requests with variables, or write more advanced assertions with JavaScript and the Chai Assertion library.

Testing Conditional Webhooks

Clearbit is one of our favorite new services. We make heavy use of their Enrichment API for qualifying leads. When looking up an email address, sometimes you get an immediate response (if it has been looked up recently) but other times you'll get a callback once the data has been retrieved. Using incoming requests combined with a condition, we can test this scenario as well:

Runscope Blog

责编内容by:Runscope Blog (源链)。感谢您的支持!

您可能感兴趣的

Java 8 Date-Time API 详解 从Java版本1.0开始就支持日期和时间,主要通过 java.util.Date 类。 但是, Date 类设计不佳。 例如, Date 中的月份从1开始,但...
HTTP API Problem Details in ASP.NET Core If you’ve been writing HTTP API’s, you likely have needed to return excepti...
Pusher Api for Swift 3 hangs during connection I have integrated the Pusher framework for my application in Swift 3 usin...
第二届阿里云API应用创新大赛获奖名单已揭晓... 第二届阿里云API应用创新大赛决赛已于2018年4月8日在阿里巴巴淘宝城圆满落幕,银杏谷、IDG 资本、财通资本、迭代资本四家 VC 被吸引至现场,挖掘API经...
What’s New in the ArcGIS API for JavaScript (versi... Our July updates to the ArcGIS API for JavaScript versions 4.8 and 3.25 are now ...