Text API

Description

Generate a random english text snippet based on the request parameters. The text is generated using Markov chains and will have embedded randomness. This endpoint is very useful for creating placeholder, test or mocking data.

Endpoint

> GET https://api.jsonrepo.com/v1/compute/generator/text

Headers

Field Description
api_key Required Your API Key

Parameters

Field Type Description
language String Optional Desired output language
Default: en
Accepts: en for English or lat for Latin (Lorem Ipsum)
length Integer Optional Maximum generated text length
Default: 200
Min: 20
Max: 20000

Length Restrictions:

The algorithm will create a string approximating length the best it can. But depending on the randomness of the generation seed it may fall short. This consideration must be taken into account when using this endpoint.

Additionally, extremely small length values (example 20) could lead to incomplete sentences as there are not enough characters in the text-space to generate a full sentence.

Randomness Factors:

The text is generated using Markov chains and will have embedded randomness. This endpoint should not be used for anything mission critical. An appropriate use-case for this API would be generating dummy text for testing user interface interactions.

Response

A successful request will result in a populated payload field with the expected output.

A failed request will result in an error output as detailed in Error Rules. If the endpoint validation fails due to missing, badly formatted or invalid parameters, the endpoint will return HTTP code 400 along with a message detailing the error.

See the examples section for more information.

Request

  • Curl
// Generate a latin text of `length` 5000

curl -G \
https://api.jsonrepo.com/v1/compute/generator/text \
-H "api_key: {YOUR_API_KEY_HERE}" \
--data-urlencode "language=lat" \ 
--data-urlencode "length=5000" 

Success Response

{
    "http_code": 200,
    "http_message": "Ok",
    "message": "Successful execution",
    "payload": {
        "snippet": {
            "text": "Maiores quia veniam est corrupti. Ut sint qui quasi [...] Laboriosam nihil quia sed nostrum. Ut eum a impedit deserunt.",
            "length": 4922
        }
    }
}

Error Response Examples

// Request with badly formatted `length` parameter

{
    "http_code": 400,
    "http_message": "Bad Request",
    "message": "Malformed request: `length` must be an integer in the range of 20 (min) and 20000 (max).",
    "payload": []
}

// Request with unrecognized `language`

{
    "http_code": 400,
    "http_message": "Bad Request",
    "message": "Malformed request: `language` parameter accepts only `en` or `lat`. Unrecognized value `arabic`.",
    "payload": []
}