Modern JavaScript (Fetch)
If you, for example, want to create a fake user:
fetch("https://reqres.in/api/users", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
},
body: JSON.stringify({
name: "paul rudd",
movies: ["I Love You Man", "Role Models"]
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error("Error:", error));
For which the response to this request will be...
{
"name":"paul rudd",
"movies":[
"I Love You Man",
"Role Models"
],
"id":"243",
"createdAt":"2025-01-15T12:09:05.255Z"
}
You can see that the API has sent us back whatever user
details we sent it, plus an
id &
createdAt key for our use.
Async/Await JavaScript
If you've already got your own application entities, ie.
"products", you can send them in the endpoint URL, like
so:
async function getProduct() {
try {
const response = await fetch("https://reqres.in/api/products/3", {
headers: {
"Authorization": "Bearer YOUR_API_KEY"
}
});
const data = await response.json();
console.log(data);
} catch (error) {
console.error("Error:", error);
}
}
getProduct();
It would be impossible for Reqres to know your
application data, so the API will respond from a sample
set of Pantone colour data
{
"data":{
"id":3,
"name":"true red",
"year":2002,
"pantone_value":"19-1664"
}
}
It's entirely possible to get sample data into your
interface in seconds!