Defines the shape of a HAL resource entity with typed data and links.
Entity is the core type definition for resources in a HATEOAS API. It combines:
Actions are discovered through link relations using state.actionFor(rel). Links that have associated HAL-Forms templates can be used as actions.
state.actionFor(rel)
import { Entity, Collection } from '@hateoas-ts/resource';// Simple entity with self linktype Post = Entity< { id: string; title: string; content: string }, { self: Post; author: User }>;// Entity with collection links and action linkstype User = Entity< { id: string; name: string; email: string }, { self: User; posts: Collection<Post>; 'create-post': Post; // Action link (has HAL-Forms template) }>;// Usageconst user = await client.go<User>('/users/123').get();console.log(user.data.name); // Type-safe access to dataconst posts = await user.follow('posts').get(); // Type-safe link navigation// Execute action through link relationif (user.hasActionFor('create-post')) { const action = user.actionFor('create-post'); await action.submit({ title: 'New Post' });} Copy
import { Entity, Collection } from '@hateoas-ts/resource';// Simple entity with self linktype Post = Entity< { id: string; title: string; content: string }, { self: Post; author: User }>;// Entity with collection links and action linkstype User = Entity< { id: string; name: string; email: string }, { self: User; posts: Collection<Post>; 'create-post': Post; // Action link (has HAL-Forms template) }>;// Usageconst user = await client.go<User>('/users/123').get();console.log(user.data.name); // Type-safe access to dataconst posts = await user.follow('posts').get(); // Type-safe link navigation// Execute action through link relationif (user.hasActionFor('create-post')) { const action = user.actionFor('create-post'); await action.submit({ title: 'New Post' });}
The data payload type (resource properties)
Record mapping link relation names to their target entity types
The resource's data payload containing its properties
Available link relations to other resources (HATEOAS navigation and actions)
Defines the shape of a HAL resource entity with typed data and links.
Entity is the core type definition for resources in a HATEOAS API. It combines:
Actions are discovered through link relations using
state.actionFor(rel). Links that have associated HAL-Forms templates can be used as actions.Example