@hateoas-ts/resource - v1.4.3
    Preparing search index...

    Interface Entity<TData, TLinks>

    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:

    • data: The resource's payload/properties
    • links: Available navigation links to related resources (includes action links)

    Actions are discovered through link relations using state.actionFor(rel). Links that have associated HAL-Forms templates can be used as actions.

    import { Entity, Collection } from '@hateoas-ts/resource';

    // Simple entity with self link
    type Post = Entity<
    { id: string; title: string; content: string },
    { self: Post; author: User }
    >;

    // Entity with collection links and action links
    type User = Entity<
    { id: string; name: string; email: string },
    {
    self: User;
    posts: Collection<Post>;
    'create-post': Post; // Action link (has HAL-Forms template)
    }
    >;

    // Usage
    const user = await client.go<User>('/users/123').get();
    console.log(user.data.name); // Type-safe access to data
    const posts = await user.follow('posts').get(); // Type-safe link navigation

    // Execute action through link relation
    if (user.hasActionFor('create-post')) {
    const action = user.actionFor('create-post');
    await action.submit({ title: 'New Post' });
    }
    interface Entity<
        TData extends SafeAny = SafeAny,
        TLinks extends Record<string, Entity> = Record<string, SafeAny>,
    > {
        data: TData;
        links: TLinks;
    }

    Type Parameters

    • TData extends SafeAny = SafeAny

      The data payload type (resource properties)

    • TLinks extends Record<string, Entity> = Record<string, SafeAny>

      Record mapping link relation names to their target entity types

    Index

    Properties

    Properties

    data: TData

    The resource's data payload containing its properties

    links: TLinks

    Available link relations to other resources (HATEOAS navigation and actions)