This 4-API allows you to:
Available Methods
Routes for each collection (quotes, colors,
words):
GET /<collection> → all items + countGET /<collection>/:id → one item by IDGET /<collection>/random → one random itemGET /<collection>/random/:n → n random items + count
Base URL: /words
Description: Fetch words along with their definition and grammatical figure.
GET /words → Fetch all wordsGET /words/2 → Fetch the word where id = 2GET /words/random → Fetch a random wordGET /words/random/5 → Fetch 5 random words
{
"status": "OK",
"data": [
{
"id": 1,
"name": "phosphenes",
"figure": "n.",
"definition": "the colors or 'stars' you see when you rub your eyes"
}
]
}
{
"status": "OK",
"data": [
{
"id": 1,
"quote": "Dreaming, after all, is a form of planning",
"author": "Gloria Steinem"
}
]
}
{
"status": "OK",
"data": [
{
"id": 1,
"bg": "#f4f0ea",
"color": "#544b43"
}
]
}
import requests
import json
url = "https://fourapi.onrender.com/quotes/random"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
print(json.dumps(data, indent=2))
else:
print("Error:", response.status_code)
fetch("https://fourapi.onrender.com/words/random")
.then(response => response.json())
.then(data => {
console.log("Fetched word:");
console.log(JSON.stringify(data, null, 2));
})
.catch(error => console.error("Error:", error));
Add this dependency in your pom.xml:
<dependency> <groupId>com.konghq</groupId> <artifactId>unirest-java</artifactId> <version>3.14.5</version> </dependency>
Example Java code:
import kong.unirest.HttpResponse;
import kong.unirest.JsonNode;
import kong.unirest.Unirest;
public class FourApiExample {
public static void main(String[] args) {
HttpResponse<JsonNode> response = Unirest.get("https://fourapi.onrender.com/colors/random")
.asJson();
System.out.println("Response:");
System.out.println(response.getBody().toPrettyString());
}
}