Mock REST API
Mock Your Backend REST Server


Mock REST API generates API responses for testing purposes. You decide what to return: locations, names, dates, numbers, social security numbers, credit card numbers, and more. Every call will produce random data of the specified type and class. A single call can include a mix of properties, custom schema, and various levels of nesting. Please consult the Roadmap page for planned release dates of new services.

Example POST request to the Mock API's Schema endpoint:

{
 "headers": {
  "auth": "51349d7defd9351ac",
  "Content-Type": "application/json"
 },
 "body": {
  "record": {
   "data": {
    "@rec_id": {
     "type": "number",
     "digits": "4",
     "records": 1
    },
    "@timestamp": {
     "type": "datetime",
     "min": "Jan-01-2020 00:00",
     "max": "Aug-01-2020 00:00",
     "format": "%b-%d-%Y %H:%M",
     "records": 1
    }
   },
   "person": {
    "info": {
     "@fname": {
      "type": "name",
      "portion": "first",
      "gender": "f",
      "region": "uk",
      "records": 1
     },
     "@lname": {
      "type": "name",
      "portion":"last",
      "gender": "0",
      "region": "uk",
      "records": 1
     }
    },
    "purchase": {
     "@number_array": {
      "type": "int",
      "min": 1,
      "max": 100,
      "records": 3
     }
    }
   }
  }
 }
}

(Click Send again for a different response)
Example response:

SUPPORTED API MANAGERS

POSTMAN
Check out our collection on Postman or read our blog post on how to get started!

GENERAL API DOCUMENTATION

Authentication & Quota
To start using the app, you need to register with your email and get your unique authorization token. The token has to be included in all your REST requests. For a start every registered user gets 1,000 free requests. To get extra 10,000 requests, fill out our anonymous mini-survey on your intended use of Random Key.

Headers
Make sure to include the content type and the authentication token in your request headers:

{
 "headers": {
  "auth": "[your token]" ,
  "Content-Type": "application/json"
 }
}

Methods Reference
GET METHODS:
Quota

POST METHODS:
Mock Schema

SUPPORTED REGIONS

About Regions
Some methods, such as Names and Locations support localized responses. The region can be specified in the request body.
Available regions, in alphabetical order: Australia, Belgium, Canada, Denmark, France, Germany, India, Italy, Netherlands, Poland, Russia, Spain, Sweden, Switzerland, United Kingdom, United States

Australia
Country code: "au"
Supports: Phone Number

Belgium
Country code: "be"
Supports: Name, First Name, Last Name, Full Name, Location, Phone Number

Canada
Country code: "ca"
Supports: Phone Number

Denmark
Country code: "dk"
Supports: Phone Number

France
Country code: "fr"
Supports: Name, First Name, Last Name, Full Name, Location, Phone Number, SSN

Germany
Country code: "de"
Supports: Name, First Name, Last Name, Full Name, Location, Phone Number

India
Country code: "in"
Supports: Phone Number

Italy
Country code: "it"
Supports: Name, First Name, Last Name, Full Name, Location, Phone Number

Netherlands
Country code: "nl"
Supports: Name, First Name, Last Name, Full Name, Location, Phone Number

Poland
Country code: "pl"
Supports: Phone Number

Spain
Country code: "es"
Supports: Phone Number

Sweden
Country code: "se"
Supports: Phone Number

Switzerland
Country code: "ch"
Supports: Phone Number

Russia
Country code: "ru"
Supports: Name, First Name, Last Name, Full Name, Location, Phone Number, IRP

UK
Country code: "uk"
Supports: Name, First Name, Last Name, Full Name, Location, Phone Number, NIN

US
Country code: "us"
Supports: Name, First Name, Last Name, Full Name, Location, Phone Number, SSN

GET METHODS

Quota
Endpoint: https://random.api.randomkey.io/v1/quota
A GET method for checking the request quota.

POST METHODS

Mock Schema
Endpoint: https://mock.api.randomkey.io/v1/schema
Requires: N/A
Returns: N/A
A POST method for producing a test response matching the schema defined in the request. The schema will be returned as-is, with the exception of the elements marked as required to be randomized. Such items need to be prepended by an "@" sign. The sign is removed in the response. The schema can include various nesting levels and various objects. Each item marked for randomization is given a custom name, the data type to be returned, and the number of instances to be generated. The method generates up to 100 items per request. Each item can carry up to a 100 elements. Note that the cost of a request is calculated as number of records X number of items, e.g. 2 records with 3 items will result in 6 requests deducted from the quota.

Allowed properties include: Integer, Double, Number, Regex, Boolean, Array, Element, Name, Email Address, Phone Number, Location, National Insurance Number, Social Security Number, Numéro de Sécurité Sociale, Internal Russian Passport - Паспорт гражданина Российской Федерации, Credit Card Number, Date, Date & Time, Time
Refer to each property's documentation for details on how to include it in your REST calls.

This is how an example request will look like:

{
 "record": {
  "data": {
   "@rec_id": {
    "type": "number",
    "digits": "4",
    "records": 1
   },
   "@timestamp": {
    "type": "datetime",
    "min": "Jan-01-2020 00:00",
    "max": "Aug-01-2020 00:00",
    "format": "%b-%d-%Y %H:%M",
    "records": 1
   }
  },
  "person": {
   "info": {
    "@fname": {
     "type": "name",
     "portion": "first",
     "gender": "f",
     "region": "uk",
     "records": 1
    },
    "@lname": {
     "type": "name",
     "portion":"last",
     "gender": "0",
     "region": "uk",
     "records": 1
    }
   },
   "purchase": {
    "@number_array": {
     "type": "int",
     "min": 1,
     "max": 100,
     "records": 3,
     "nulls": true,
    }
   }
  }
 }
}


You will receive data in the following format:

{
 "record": {
  "data": {
   "rec_id": "5932",
   "timestamp": "Jul-15-2020 04:29"
  },
  "person": {
   "info": {
    "fname": "Elizabeth",
    "lname": "Regis"
   },
   "purchase": {
    "number_array": [32, 78, null]
   }
  }
 }
}

SUPPORTED PROPERTIES

Integer
Type: int
Requires: type (string)
Optional: min (int), max (int), records (int), nulls (boolean)
Accepts: nulls: [ true | false ]
Defaults: min: 1, max: 100, records: 1, nulls: false
Returns: (int)
Specifying this property produces a random integer within the given range.

This is how to include the property in a Mock Schema request:

{
 "@label": {
  "type": "int",
  "min": -10,
  "max": 10,
  "records": 1
 }
}


You will receive data in the following format:

{
 "label": 2
}

Double
Type: double
Requires: type (string)
Optional: min (int), max (int), records (int), nulls (boolean)
Accepts: nulls: [ true | false ]
Defaults: min: 1, max: 100, records: 1, nulls: false
Returns: (double)
Specifying this property produces a random double within the given range.

This is how to include the property in a Mock Schema request:

{
 "@label": {
  "type": "double",
  "min": -2.2,
  "max": 2.1,
  "records": 1
 }
}


You will receive data in the following format:

{
 "label": -0.1
}

Number
Type: number
Requires: type (string)
Optional: digits (int), records (int), nulls (boolean)
Accepts: nulls: [ true | false ]
Defaults: digits: 5, records: 1, nulls: false
Returns: (string)
Specifying this property produces a random number of the specified length. The generated string may include leading zeros.

This is how to include the property in a Mock Schema request:

{
 "@label": {
  "type": "number",
  "digits": 5,
  "records": 1
 }
}


You will receive data in the following format:

{
 "label": "01299"
}

Regex
Type: regex
Requires: type (string)
Optional: regex (string), records (int), nulls (boolean)
Accepts: nulls: [ true | false ]
Defaults: regex: "\\w", records: 1, nulls: false
Returns: (string)
Specifying this property produces a random string matching the provided regular expression. Escape the tokens that use a backslash with an additional backslash. Generates up to 10,000 records per request. If the null flag is set to true, a null value will be produced 10% of time. The most common regular expressions are supported, including:
A single character of a, b, or c: [abc]
A character except a, b, or c: [^abc]
A character in the range a-z: [a-z]
A character in the range a-z or A-Z: [a-zA-Z]
A single character: .
A non-whitespace character: \S
A digit: \d
A non-digit: \D
A word character: \w
A non-word character: \W
Exactly 3 of a: a{3}
3 or more of a: a{3,}
Between 3 and 6 of a: a{3,6}
Either a or b: a|b


This is how to include the property in a Mock Schema request:

{
 "@label": {
  "type": "regex",
  "regex": "\\d\\d [A-Z]{3}",
  "records": 1
 }
}


You will receive data in the following format:

{
 "label": "02 UIK"
}

Boolean
Type: boolean
Requires: type (string)
Optional: records (int), nulls (boolean)
Accepts: nulls: [ true | false ]
Defaults: records: 1, nulls: false
Returns: (boolean)
Specifying this property produces a random boolean: True or False. If the null flag is set to true, a null value will be produced 10% of time.

This is how to include the property in a Mock Schema request:

{
 "@label": {
  "type": "boolean",
  "records": 1
 }
}


You will receive data in the following format:

{
 "label": false
}

Array
Type: array
Requires: type (string)
Optional: records (int), nulls (boolean), array (array), elements (int)
Accepts: nulls: [ true | false ]
Defaults: array: ["Specify your array"], elements: 2, records: 1, nulls: false
Returns: (array)
Specifying this property produces a random selection of elements from the provided array. The number of elements to return per array can be specified. Arrays can comprise of various data types. If the null flag is set to true, a null value will be produced 10% of time.

This is how to include the property in a Mock Schema request:

{
 "@label": {
  "type": "array",
  "elements": 2,
  "array": ["JFK","LHR","HKG","LAX","FRA"]
 }
}


You will receive data in the following format:

{
 "label": [
  "HKG",
  "LHR"
 ]
}

Element
Type: element
Requires: type (string)
Optional: nulls (boolean), array (array)
Accepts: nulls: [ true | false ]
Defaults: array: ["Specify your array"], nulls: false
Returns: ( string | int | double | float | date | boolean | None )
Specifying this property produces a random element from the provided array. Arrays can comprise of various data types. If the null flag is set to true, a null value will be produced 10% of time.

This is how to include the property in a Mock Schema request:

{
 "@label": {
  "type": "element",
  "array": ["JFK","LHR","HKG","LAX","FRA"]
 }
}


You will receive data in the following format:

{
 "label": "LAX"
}

Name
Type: name
Requires: type (string)
Optional: portion (string), gender (string), region (string), records (int), nulls (boolean)
Accepts: nulls: [ true | false ], portion: [ "first" | "last" | "full" ], gender: [ "f" | "m" | "0" ], region: see Supported Regions
Defaults: portion: "first", gender: "0", region: "us", records: 1, nulls: false
Returns: (string)
Specifying this property produces a name of the specified name portion (first, last) and gender (male, female, N/A). The method is regional, i.e. the region has to be specified in the request's body.

This is how to include the property in a Mock Schema request:

{
 "@label": {
  "type": "name",
  "portion": "first",
  "gender": "f",
  "region": "de",
  "records": 1
 }
}


You will receive data in the following format:

{
 "label": "Ila"
}

Email Address
Type: email
Requires: type (string)
Optional: records (int), nulls (boolean)
Accepts: nulls: [ true | false ]
Defaults: records: 1, nulls: false
Returns: (string)
Specifying this property produces an email address.

This is how to include the property in a Mock Schema request:


 "@label": {
  "type": "email"
  "records": 1
 }
}


You will receive data in the following format:

{
 "label": "6ab074a7a241@live.com"
}

Phone Number
Type: phone
Requires: type (string)
Optional: records (int), nulls (boolean), country_prefix (boolean), idd (string), trunk (string), region (string)
Accepts: nulls: [ true | false ], country_prefix: [ true | false ], idd: [ "" | "00" | "01" | "011" | "010" | "0011" | "810" | "+" ], region: see Supported Regions
Defaults: records: 1, nulls: false, country_prefix: false, idd: "", , trunk: "", region: "us"
Returns: (string)
Specifying this property produces a mobile phone number. The phone number can include a trunk prefix, an IDD code, and/or a country code prefix. By default, only the phone number is returned. The method is regional, i.e. the region has to be specified in the request's body. Consult the Supported Regions section for valid country codes.

This is how to include the property in a Mock Schema request:


 "@label": {
  "type": "phone"
  "idd": "+",
  "country_prefix": true
 }
}


You will receive data in the following format:

{
 "label": "+31634526974"
}

Location
Type: location
Requires: type (string)
Optional: portion (string), region (string), records (int), nulls (boolean)
Accepts: portion: [ "full" | "city" | "streetcity" | "streetcitystate" | "cityzip" ], nulls: [ true | false ], region: see Supported Regions
Defaults: portion: "full", region: "us", records: 1, nulls: false
Returns: ( array | string )
Specifying this property produces an address, comprising of a street, city, state (US only), postcocode, or a combination of those as specified in the request. The method is regional, i.e. the region has to be specified in the request's body. Consult the Supported Regions section for valid country codes.

This is how to include the property in a Mock Schema request:

{
 "@label": {
  "type": "location",
  "region": "de",
  "portion": "full",
  "records": 1
 }
}


You will receive data in the following format:

{
 "label": [
  "Buchsbaumweg 56",
  "Berlin",
  "12357"
 ]
}

National Insurance Number
Type: nin
Requires: type (string)
Optional: records (int), nulls (boolean)
Accepts: nulls: [ true | false ]
Defaults: records: 1, nulls: false
Returns: (string)

Specifying this property produces a random British National Insurance Number. The NIN numbers have been generated by following the HMRC specification for a valid NIN format.

This is how to include the property in a Mock Schema request:

{
 "@label": {
  "type": "nin",
  "records": 1
 }
}


You will receive data in the following format:

{
 "label": "KM440262C"
}

Social Security Number
Type: ssn
Requires: type (string)
Optional: records (int), nulls (boolean)
Accepts: nulls: [ true | false ]
Defaults: records: 1, nulls: false
Returns: (string)

Specifying this property produces random Social Security Numbers. The SSN numbers have been generated by following the SSA specification for a valid SSN format.

This is how to include the property in a Mock Schema request:

{
 "@label": {
  "type": "ssn",
  "records": 1
 }
}


You will receive data in the following format:

{
 "label": "61084657"
}

Numéro de Sécurité Sociale
Type: nss
Requires: type (string)
Optional: gender (string), portion (string), records (int), nulls (boolean)
Accepts: nulls: [ true | false ], gender: [ "0" | "f" | "m" ], portion: [ "full" | "number" ], records: 1, nulls: false
Defaults: gender: "0", portion: "full", records: 1, nulls: false
Returns: (array)

Specifying this property produces random French social security number, i.e. numéro de sécurité sociale. The method returns a Date of Birth based on the information derived from the NSS, unless specified otherwise. The NSS numbers have been generated by following the INSEE specification for a valid NSS format. You can specify the gender in the request (female, male, or random). This is how to include the property in a Mock Schema request:

{
 "@label": {
  "type": "nss",
  "gender": "0",
  "portion": "full",
  "records": 1
 }
}


You will receive data in the following format:

{
 "label": [
  "467083229024132",
  "21/08/67"
 ]
}

Internal Russian Passport
Type: irp
Requires: type (string)
Optional: records (int), nulls (boolean)
Accepts: nulls: [ true | false ]
Defaults: records: 1, nulls: false
Returns: (string)

Specifying this property produces random internal Russian passport number, i.e. Паспорт гражданина Российской Федерации. The numbers have been generated by following the MIA of Russia's specification for valid passport numbers.

This is how to include the property in a Mock Schema request:

{
 "@label": {
  "type": "irp",
  "records": 1
 }
}


You will receive data in the following format:

{
 "label": "9417868965"
}

Credit Card Number
Type: ccn
Requires: type (string)
Optional: portion (string), records (int), nulls (boolean), valid (boolean), luhn (boolean)
Accepts: nulls: [ true | false ], portion: [ "full" | "number" ], valid: [ true | false ], luhn: [ true | false ]
Defaults: records: 1, nulls: false, portion: "number", valid: true, luhn: true
Returns: ( string | array )

Specifying this property produces random Payment Card Numbers. The card numbers will pass or fail the Luhn check as specified. The cards will carry an invalid date if the valid flag is set to False. The generated response returns card numbers by default but can be configured to include the expiry month and the security code. The pool of supported IIN's includes the biggest financial institutions issuing credit and debit cards: American Express, Diners Club, China UnionPay, VISA, MasterCard, Maestro, and Discover. The PANs generated follow the structure supported by their vendor, e.g. American Express have exactly 15 digits.

This is how to include the property in a Mock Schema request:

{
 "@label": {
  "type": "ccn",
  "portion": "full",
  "records": 1
 }
}


You will receive data in the following format:

{
 "label": [
  "50213940241316509",
  "02/22",
  "357"
 ]
}

Date
Type: date
Requires: type (string)
Optional: min (string), max (string), format (string), records (int), nulls (boolean)
Accepts: nulls: [ true | false ]
Defaults: min: "01-Jan-1990", max: "31-Dec-2020", format: "%d-%b-%Y", records: 1, nulls: false
Returns: (string)
Specifying this property produces a random date within the given range and in the format specified. The format has to match that of the provided range. The function accepts strftime() and strptime() format codes. The full list of available date format codes can be found in the Python documentation.

This is how to include the property in a Mock Schema request:

{
 "@label": {
  "type": "date",
  "min": "01-May-1990",
  "max": "02-Jun-2020",
  "format": "%d-%b-%Y",
  "records": 1
 }
}


You will receive data in the following format:

{
 "label": "21-Sep-1992"
}

Datetime
Type: datetime
Requires: type (string), min (string), max (string), format (string)
Optional: min (string), max (string), format (string), records (int), nulls (boolean)
Accepts: nulls: [ true | false ]
Defaults: min: "01-Jan-1990 00:00", max: "31-Dec-2020 23:59", format: "%d-%b-%Y %H:%M", records: 1, nulls: false
Returns: (string)
Specifying this property produces a random date and time within the given range and in the format specified. The format has to match that of the provided range. The function accepts strftime() and strptime() format codes. The format has to match that of the provided range. The full list of available date format codes can be found in the Python documentation.

This is how to include the property in a Mock Schema request:

{
 "@label": {
  "type": "datetime",
  "min": "31/Dec/1999 00:00",
  "max": "31/Dec/2000 00:00",
  "format": "%d/%b/%Y %I:%M",
  "records": 1
 }
}


You will receive data in the following format:

{
 "label": "16/Apr/2000 19:22"
}

Time
Type: time
Requires: type (string), min (string), max (string), format (string)
Optional: min (string), max (string), format (string), records (int), nulls (boolean)
Accepts: nulls: [ true | false ]
Defaults: min: "01-Jan-1990 00:00", max: "31-Dec-2020 23:59", format: "%d-%b-%Y %H:%M", records: 1, nulls: false
Returns: (string)
Specifying this property produces random time within the given range and in the format specified. The format has to match that of the provided range. The function accepts strftime() and strptime() format codes. The format has to match that of the provided range. The full list of available date format codes can be found in the Python documentation.

This is how to include the property in a Mock Schema request:

{
 "@label": {
  "type": "time",
  "min": "00:00:00",
  "max": "02:00:00",
  "format": "%I:%M:%S",
  "records": 1
 }
}


You will receive data in the following format:

{
 "label": "01:59:02"
}