Skip to main content
Version: 7.3

Define Async Methods (Endpoints)

Endpoints are the methods of your data. Entities are a type of Schema, which define the data model. Resources are a collection of endpoints around one schema.

npm install --save @rest-hooks/rest
import { createResource, Entity } from '@rest-hooks/rest';
export class Todo extends Entity {
id = 0;
userId = 0;
title = '';
completed = false;
pk() {
return `${}`;
static key = 'Todo';
export const TodoResource = createResource({
urlPrefix: '',
path: '/todos/:id',
schema: Todo,
import { TodoResource } from './api/Todo';
// GET
TodoResource.get({ id: 5 });
// GET
TodoResource.create({ title: 'my todo' });
// PUT
TodoResource.update({ id: 5 }, { title: 'my todo' });
TodoResource.partialUpdate({ id: 5 }, { title: 'my todo' });
TodoResource.delete({ id: 5 });

It's highly encouraged to design APIs with consistent patterns. Because of this, you can extend our protocol specific helpers. After choosing your protocol, you can read up on the full docs for reach protocol REST, GraphQL, Image/binary, Websockets+SSE

To use your own protocol or existing helpers, use the lower-level primitives from @rest-hooks/endpoint like Endpoint and schema.Entity. [See Promise tab above]