Quick Start

Try the following cURL command in your Terminal that sends a GET request. The JSON response specified in __cp_response query string will be returned after 3 seconds which is specified in __cp_delay query string.

curl --request GET \
  --url 'https://use.coparrot.dev/api/whatever/path?__cp_response=%7B%22id%22%3A12%2C%22name%22%3A%22Joey%22%2C%22gender%22%3A%22male%22%7D&__cp_delay=3'

For more options, keep on reading.

Prerequisite

To use Coparrot service, you need to have a license key. Get a license key by subscribing to a Coparrot membership here. Without the license key, you can still use the service but your access will be rate limited.

Usage

Base URL

To use Coparrot service, you need to set the base url of your app to https://use.coparrot.dev/api


Using Query Strings

You can specify the responses you want by setting the __cp_response query string. For example, calling the following URL

https://use.coparrot.dev/api/some/path/to/a/resource?__cp_response=hello%20world
will return the text hello world.

The following query string keys are valid:

KeyValue
__cp_license_keyRequired. The value of this key should be the license key you got when you subscribed to Coparrot membership.
__cp_responseAny text. If the value is a valid JSON string, the returned response will have application/json content type
__cp_delayDelay in seconds. The response will be returned to your app after specified seconds. Note that the delay won't be exact.
__cp_contentTypeAt this moment, the value should be either json or text
__cp_statusSpecify the HTTP status code of the response. Default is 200.
__cp_maxDelaySpecify the maximum delay in seconds. The delay will be set in random.
__cp_minDelaySpecify the minimum delay in seconds. The delay will be set in random. If there's no __cp_maxDelay, the default is random number between __cp_minDelay and 10 seconds.
__cp_redirectSpecify the url to redirect to.
__cp_setCookiesSpecify the cookies to set. The value should be a valid JSON string of an array of objects with keys: name, value, and options. The options should be an object with keys defined in nookies.
__cp_deleteCookiesSpecify the cookies to destroy. The value should a comma separated keys.

For example, the following URL

https://use.coparrot.dev/api/whatever/path?__cp_response=%7B%22id%22%3A12,%22name%22%3A%22Joey%22,%22gender%22%3A%22male%22%7D&__cp_license_key=valid-license-key&__cp_delay=3
will return the following JSON response after 3 seconds
{
	"id": 12,
	"name": "Joey",
	"gender": "male"
}

If you use cURL and the value of your __cp_response query string is a JSON string, you should encode it first to a URL-encoded format. Moreover, to reduce the number of characters, you can minify the JSON string first. I've made an online JSON minifier and URL encoder for you to try here.

But if your app is a Node.js app, you can use the encodeURIComponent function.

If you use Postman or Insomnia, you don't need to encode the JSON string first.


Using HTTP Headers

As an alternative to using query strings, you can also specify the parameters using HTTP headers.

The following header keys are valid:

KeyValue
X-CP-LICENSE-KEYRequired. The value of this key should be the license key you got when you subscribed to Coparrot membership.
X-CP-RESPONSEAny text. If the value is a valid JSON string, the returned response will have application/json content type. IMPORTANT: Since new line is not allowed in the request header, you should encode the value of this key first. In JavaScript, you can use encodeURIComponent.
X-CP-DELAYDelay in seconds. The response will be returned to your app after specified seconds. Note that the delay won't be exact.
X-CP-CONTENT-TYPEAt this moment, the value should be either json or text
X-CP-STATUSSpecify the HTTP status code of the response. Default is 200.
X-CP-MAX-DELAYSpecify the maximum delay in seconds. The delay will be set in random.
X-CP-MIN-DELAYSpecify the minimum delay in seconds. The delay will be set in random. If there's no __cp_maxDelay, the default is random number between __cp_minDelay and 10 seconds.
X-CP-REDIRECTSpecify the url to redirect to.
X-CP-SET-COOKIESSpecify the cookies to set. The value should be a valid JSON string of an array of objects with keys: name, value, and options. The options should be an object with keys defined in nookies.
X-CP-DELETE-COOKIESSpecify the cookies to destroy. The value should a comma separated keys.

For example, the following cURL command

curl --request POST \
  --url https://use.coparrot.dev/api/whatever/path \
  --header 'X-CP-DELAY: 1' \
  --header 'X-CP-LICENSE-KEY: valid-license-key' \
  --header 'X-CP-RESPONSE: {"result":"ok"}'
will return a valid JSON string after 1 second:
{
	"result": "ok"
}


Templates

You can use some template tags to generate string dynamically in __cp_response or X-CP-RESPONSE. Check the template documentation.