BadAPI

BadAPI allows you to simulate misbehaving APIs. This is useful if your site relies on the availability of service X, and you want to ensure that any downtime experienced by that service has minimal impact on your own application.

How to use

Replace the HTTP endpoint URL for the API you wish to test with the URL 'http://badapi.trib.tv/req'. Append arguments to the URL query string parameters, as indicated below to control the bahaviour that you get from the API simulator. Arguments should be separated by ampersands (&) if you want to provide more than one argument, and should be URL encoded if necessary.

Arguments

PrefixFormatExampleDescription
waitIntegerwait=25Causes the request to hang for the specified number of seconds before returning output. Useful for simulating sluggish response, or checking that timeouts behave as expected. Max 30 seconds.
respIntegerresp=500Causes the specified HTTP response status code to be used in the response, eg 500 Internal Server Error. Any valid HTTP response status code can be used. Invalid codes are ignored.
opStringop=json1Specifies the output to send in response to the request. The choice of outputs is as shown below.
ctStringct=htmlSpecifies a content-type header to include in the response. Shortcuts are html (text/html), css (text/css), jpg (image/jpg), gif (image/gif), png (image/png), text (text/plain), xhtml (application/xhtml+xml), pdf (application/pdf), bin (application/octet-stream). Any unrecognised string will be used as given.
csStringcs=utf8Specifies a character set to include in the content-type header of the response. Shortcuts are utf (UTF-8), latin1 (ISO-8859-1), asc (US-ASCII), win1252 (windows-1252). Any unrecognised string will be used as given.

Outputs

KeywordDescription
headersPretty print the headers of the inbound request
bodyEcho the body of the inbound request
queryEcho the querystring of the inbound request
requestPretty print the inbound request
errstringA simple error message
formvarsURL-encoded form data
jsdocwriteA simple JavaScript document.write statement. This is intended to be used to test the ability to content management systems to embed script includes
json1Valid JSON test string, UTF-8 encoded with non-ASCII characters and Unicode escape sequences, spaced with tabs, newlines and spaces.
phpserialPHP Serialised data

Examples

About

Created by Andrew Betts. Comments to andrew@trib.tv.