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

    Class Links<T>

    Container for managing a collection of hypermedia links.

    Provides methods for adding, retrieving, and querying links by their relation type. Supports multiple links per relation.

    const links = new Links('https://api.example.com/users/123');

    // Add links
    links.add('self', '/users/123');
    links.add({ rel: 'posts', href: '/users/123/posts' });

    // Query links
    if (links.has('posts')) {
    const postLink = links.get('posts');
    console.log(postLink?.href);
    }

    // Multiple links with same rel
    const allItems = links.getMany('item');

    Type Parameters

    • T extends Record<string, SafeAny>

      Record type defining available link relations

    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    defaultContext: string

    Base URI for resolving relative hrefs

    Methods

    • Deletes links by relation and optionally by href.

      Parameters

      • rel: string

        The relation type to delete

      • Optionalhref: string

        Optional href to match; deletes all if not provided

      Returns void

    • Checks if any links exist with the given relation.

      Parameters

      • rel: keyof T

        The relation type to check

      Returns boolean

      true if at least one link exists with the rel