
π Documentation & Examples
Everything you need to integrate with ReqRes
π Quick Start Examples
// ReqRes API Example
const response = await fetch('https://reqres.in/', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);Using the Reqres.in Public API with JavaScript
Reqres.in is a great resource that provides a public API that you can use to build and test your applications. In this article, we'll show you how to use the Reqres.in API with JavaScript and provide some example code to get you started.
How to Get a Reqres API Key
Reqres now requires a free API key on every request β calls without one return HTTP 401 with {"error":"missing_api_key"}. (Older examples that hit the endpoints with no key no longer work.)
- Go to https://app.reqres.in/ and sign up for a free account.
- Open the API Keys page (https://app.reqres.in/api-keys) and copy your key.
- Send it in the
x-api-keyheader on every request.
curl "https://reqres.in/api/users/2" -H "x-api-key: YOUR_API_KEY"
This applies to all endpoints β for example, creating a user:
curl -X POST "https://reqres.in/api/users" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name":"John Doe","job":"Developer"}'
Reqres is still a free fake-data API for prototyping and testing (it doesn't persist changes), but the key is now mandatory on the free tier; paid plans add higher limits and features. If you get a 401, check that the x-api-key header is present and spelled correctly.
Getting Started
First, let's take a quick look at the available endpoints of the Reqres.in API.
-
GET /api/users
Returns a list of users.
-
GET /api/users/{id}
Returns a single user.
-
POST /api/users
Creates a new user.
-
PUT /api/users/{id}
Updates an existing user.
-
DELETE /api/users/{id}
Deletes an existing user.
Example Code
We'll start by using the fetch method to make our API calls. This method allows us to make network requests and handle the returned data. Here's some example code to get you started:
// Get list of users
fetch("https://reqres.in/api/users")
.then(response => response.json())
.then(data => console.log(data));
// Get a single user
fetch("https://reqres.in/api/users/2")
.then(response => response.json())
.then(data => console.log(data));
// Create a new user
fetch("https://reqres.in/api/users", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
name: "John Doe",
job: "Developer"
})
})
.then(response => response.json())
.then(data => console.log(data));
// Update an existing user
fetch("https://reqres.in/api/users/2", {
method: "PUT",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
name: "Jane Doe",
job: "Designer"
})
})
.then(response => response.json())
.then(data => console.log(data));
// Delete an existing user
fetch("https://reqres.in/api/users/2", {
method: "DELETE"
})
.then(response => console.log(response));
Conclusion
Using the Reqres.in public API with JavaScript is a great way to get started with building and testing your applications. With the available endpoints and some example code, you'll be up and running in no time. Happy coding!






