jsonplaceholder
JSONPlaceholder is a free online REST API that you can use whenever you need some fake data.
Usage
import { jsonplaceholder } from 'netzo/apis/jsonplaceholder.ts'
const api = jsonplaceholder()
Configuration
The jsonplaceholder
factory function returns an object with an API client api
.
Refer to the API documentation to get the required information.
Examples
The following examples assume you have created an api client instance.
Find todos
Find all todos.
const resultData = await api.todos.get<Todo[]>()
Get todo
Get todo by id.
const resultData = await api.todos[TODO_ID].get<Todo>()
Add todo
Add a new todo.
const data: DataAddTodo = {
userId: 1,
title: 'New task'
}
const resultData = await api.todos.post<Todo>(data)
Update todo
Update a todo by id.
const data: Todo = {
userId: 1,
title: 'Updated task',
id: TODO_ID,
completed: true
}
const resultData = await api.todos[TODO_ID].put<Todo>(data)
Delete todo
Delete a todo by id.
const resultData = await api.todos[TODO_ID].delete<{}>()