A strongly-typed TypeScript client for the ReqRes.in API service. This package provides a clean and intuitive interface for performing user management operations with full TypeScript support.
Package URL: https://www.npmjs.com/package/reqres-api
npm install reqres-api- Full TypeScript support with comprehensive type definitions
- Simple and intuitive API for user management
- Built-in error handling and response type safety
- Support for pagination
- Flexible update operations (PUT/PATCH)
- Promise-based API
import { ReqResAPI } from 'reqres-api';
// Initialize with your preferred HTTP client
const client = new ReqResAPI(yourHttpClient);const { data, error } = await client.getUsers(1);
if (data) {
console.log(`Total users: ${data.total}`);
console.log(`Current page: ${data.page}`);
console.log('Users:', data.data);
}const newUser = {
name: "John Doe",
job: "Software Engineer"
};
const { data, error } = await client.createUser(newUser);
if (data) {
console.log(`Created user with ID: ${data.id}`);
console.log(`Created at: ${data.createdAt}`);
}const updateData = {
name: "John Doe",
job: "Senior Software Engineer"
};
// Full update (PUT)
const { data: putData } = await client.updateUser(1, updateData, 'PUT');
// Partial update (PATCH)
const { data: patchData } = await client.updateUser(1, updateData, 'PATCH');const { data, error } = await client.deleteUser(1);
if (data === true) {
console.log('User successfully deleted');
}All methods return an object with either a data or an error property:
const { data, error } = await client.getUsers(1);
if (error) {
console.error('Failed to fetch users:', error);
} else {
console.log('Users:', data);
}- Node.js ES2019 or later
- TypeScript 5.0 or later (for development)
MIT
Rafael Pinto Sperafico
- Clone the repository:
git clone <your-repo-url>
cd reqres-api- Install dependencies:
npm install- Build the package:
npm run buildThis will compile the TypeScript files into JavaScript in the dist directory.
- First, make sure you have an npm account and are logged in:
npm login- Update the version number in
package.json:
npm version patch # for bug fixes
npm version minor # for new features
npm version major # for breaking changes- Build the package:
npm run build- Publish to npm:
npm publishNote: The package is configured with "publishConfig": { "access": "public" } in package.json, which means it will be published as a public package.
Contributions are welcome! Please feel free to submit a Pull Request.
- @managed-api/generic-core: ^1.2.0