While we can generate data using Faker.JS, we can also leverage artificial intelligence to produce data in a realistic and rapid manner. We can provide examples and request almost anything. The AI will deliver a JSON with our request in just seconds.
To use artificial intelligence to generate data for our mock API, it's as simple as using "//" in the code editor followed by what we want to request. For instance, let's ask for a list of football players:
//a list of football players
After a few seconds, the editor will display exactly what we requested in JSON format:
{
"players": [
{
"name": "Lionel Messi",
"age": 33,
"nationality": "Argentina"
},
{
"name": "Cristiano Ronaldo",
"age": 36,
"nationality": "Portugal"
},
{
"name": "Neymar Jr",
"age": 29,
"nationality": "Brazil"
}
]
}
That's not all; we can request more complex data. Imagine you have an endpoint at /users, but you only have one user object mocked:
{
"users": [
{
"id": 1,
"name": "test",
"age": 23
}
]
}
Now, let's say we want to add two more users and introduce a new "address" field for the users. We can request this as follows:
//get an array of 3 users with a new address field like this array
{"users": [
{
"id": 1,
"name": "test",
"age": 23
}
]
}
The API might respond with something like this:
{
"users": [
{
"id": 1,
"name": "John",
"age": 25,
"address": "123 Main St"
},
{
"id": 2,
"name": "Jane",
"age": 30,
"address": "456 Elm St"
},
{
"id": 3,
"name": "Tom",
"age": 28,
"address": "789 Oak St"
}
]
}
By using this method, we can save a significant amount of time, create APIs from scratch, and even incorporate suggestions from the AI.
Create a project