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.
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.
To use Coparrot service, you need to set the base url of your app to https://use.coparrot.dev/api
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%20worldwill return the text
hello world
.The following query string keys are valid:
Key | Value |
---|---|
__cp_license_key | Required. The value of this key should be the license key you got when you subscribed to Coparrot membership. |
__cp_response | Any text. If the value is a valid JSON string, the returned response will have application/json content type |
__cp_delay | Delay in seconds. The response will be returned to your app after specified seconds. Note that the delay won't be exact. |
__cp_contentType | At this moment, the value should be either json or text |
__cp_status | Specify the HTTP status code of the response. Default is 200 . |
__cp_maxDelay | Specify the maximum delay in seconds. The delay will be set in random. |
__cp_minDelay | Specify 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_redirect | Specify the url to redirect to. |
__cp_setCookies | Specify 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_deleteCookies | Specify 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=3will 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.
As an alternative to using query strings, you can also specify the parameters using HTTP headers.
The following header keys are valid:
Key | Value |
---|---|
X-CP-LICENSE-KEY | Required. The value of this key should be the license key you got when you subscribed to Coparrot membership. |
X-CP-RESPONSE | Any 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-DELAY | Delay in seconds. The response will be returned to your app after specified seconds. Note that the delay won't be exact. |
X-CP-CONTENT-TYPE | At this moment, the value should be either json or text |
X-CP-STATUS | Specify the HTTP status code of the response. Default is 200 . |
X-CP-MAX-DELAY | Specify the maximum delay in seconds. The delay will be set in random. |
X-CP-MIN-DELAY | Specify 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-REDIRECT | Specify the url to redirect to. |
X-CP-SET-COOKIES | Specify 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-COOKIES | Specify 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" }
You can use some template tags to generate string dynamically in __cp_response
or X-CP-RESPONSE
. Check the template documentation.