
FakeJSON
DevelopmentFake it till you make it Mock backend API for lightspeed development. Zero installations fakeJSON is ready to use out of the box. Our API endpoint is always online and ready to serve as your application’s mock backend. No database schema or engine to choose, no npm package to install, no dependencies to check for. Unlimited response possibilities Get the exact backend response you need with more than 100 different fields. If it doesn’t exist, you can even make your own field. No configuration There is no need to configure routes with API requests made to the FakeJSON API endpoint. Just configure the response directly in the JSON request payload. Fast "get to work" time You can get a fully working application in seconds. No deployment requirements to use any of fakeJSON powerful features. Simple to use There is no need to learn a new tool, language or protocol. What you enter as a payload is what you get. It’s that simple. Consistently fast responses Blazing fast, the fakeJSON API is tuned for speed. Whether it’s 50 or 50,000 units returned, your mock backend will be the least of your concerns.
📚 Documentation & Examples
Everything you need to integrate with FakeJSON
🚀 Quick Start Examples
// FakeJSON API Example
const response = await fetch('https://fakejson.com', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);
Introduction to FakeJSON public API
FakeJSON is a public API that provides mock JSON data for testing purposes. This API can be used for generating fake data for various applications such as web and mobile development. In this article, we will discuss various API examples in JavaScript that can be used to fetch fake data from the FakeJSON API.
Getting Started
To use the FakeJSON API, you need to obtain an API key. You can register a new account on FakeJSON and get the API key by following the instructions on their website. Once you have the API key, you can use it to make API requests.
API Examples
Example 1: Generating Fake Data for Users
fetch('https://app.fakejson.com/q', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer <YOUR_API_KEY>'
},
body: JSON.stringify({
token: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
data: {
firstName: '{{firstName}}',
lastName: '{{lastName}}',
email: '{{email}}',
phone: '{{phone}}',
street: '{{streetAddress}}',
city: '{{city}}',
state: '{{stateAbbr}}',
country: '{{country}}',
zip: '{{zipCode}}'
}
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error))
In this example, we are using the fetch() method to make a POST request to the FakeJSON API. We are passing our API key in the Authorization header and a JSON payload containing the data we want to generate. This will return a JSON object containing the fake data for the requested fields.
Example 2: Generating Fake Data for Products
fetch('https://app.fakejson.com/q', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer <YOUR_API_KEY>'
},
body: JSON.stringify({
token: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
data: {
productCode: '{{productCode}}',
productName: '{{productName}}',
productDescription: '{{loremIpsum}}',
productPrice: '{{numberLength 2}}.{{numberLength 2}}'
}
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error))
In this example, we are generating fake product data. We are passing the fields we want to generate in the data object. This will return a JSON object containing the fake product data.
Example 3: Generating Fake Data for Images
fetch('https://app.fakejson.com/q', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer <YOUR_API_KEY>'
},
body: JSON.stringify({
token: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
data: {
imageUrl: '{{imageUrl 300 300 animals}}',
imageDescription: '{{catchPhrase}}'
}
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error))
In this example, we are generating fake image data. We are passing the fields we want to generate in the data object. This will return a JSON object containing the fake image data.
Conclusion
FakeJSON provides a simple and easy-to-use API for generating fake data for testing purposes. In this article, we have discussed various API examples in JavaScript that can be used to fetch fake data from the FakeJSON API. These examples can be easily modified to generate custom data for your applications.
📊 30-Day Uptime History
Daily uptime tracking showing online vs offline minutes