naeemkhania-json-placeholder-sdk
v1.0.1
Published
A simple and lightweight TypeScript SDK for interacting with the JSONPlaceholder API. This library provides easy access to fetch todos and other resources from the JSONPlaceholder mock API.
Downloads
231
Readme
JSON Placeholder API SDK
A simple and lightweight TypeScript SDK for interacting with the JSONPlaceholder API. This library provides easy access to fetch todos and other resources from the JSONPlaceholder mock API.
Installation
npm install naeemkhania-json-placeholder-sdkUsage
Basic Example
import { JSONPlaceholderSDK } from 'naeemkhania-json-placeholder-sdk';
const sdk = new JSONPlaceholderSDK();
// Fetch a todo by ID
const todo = await sdk.fetchTodo(1);
console.log(todo);Response Format
The fetchTodo() method returns a todo object with the following structure:
interface IFetchTodo {
userId: number;
id: number;
title: string;
completed: boolean;
}API Reference
JSONPlaceholderSDK.fetchTodo(todoIndex: number): Promise<IFetchTodo>
Fetches a single todo item by its ID.
Parameters:
todoIndex(number): The ID of the todo to fetch (1-200)
Returns: Promise that resolves to an IFetchTodo object
Throws: Error if the request fails
Example:
try {
const todo = await sdk.fetchTodo(1);
console.log(todo.title);
} catch (error) {
console.error('Failed to fetch todo:', error);
}About JSONPlaceholder
JSONPlaceholder is a free online REST API that you can use whenever you need some fake data. It's perfect for tutorials, testing, and prototyping.
- API URL: https://jsonplaceholder.typicode.com
- Documentation: https://jsonplaceholder.typicode.com
Requirements
- Node.js 14+
- TypeScript 4.5+ (for development)
License
ISC
Author
Naeem Khania
Contributing
Feel free to submit issues and enhancement requests!
