CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-rest

tessl install tessl/npm-rest@2.0.0

RESTful HTTP client library with composable interceptor architecture for Node.js and browsers

Agent Success

Agent success rate when using this tile

76%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.29x

Baseline

Agent success rate without this tile

59%

task.mdevals/scenario-9/

HAL Resource Navigator

Build a utility that fetches and navigates HAL-formatted API resources using the rest.js HTTP client library.

Requirements

Your implementation should provide a simple interface to:

  1. Fetch HAL+JSON resources from API endpoints
  2. Follow links to related resources using relationship names
  3. Access embedded resources without additional HTTP requests

HAL (Hypertext Application Language) responses contain _links for related resources and _embedded for nested data. Your utility should leverage the rest.js library's built-in HAL support to navigate these hypermedia structures.

Test Cases

HAL Resource Fetching

  • Fetching "/api/users/1" returns a HAL resource with _links containing a self link @test

Following Links

  • Given a resource with _links.orders, following the "orders" relationship fetches the related orders resource @test
  • Following a chain of relationships like "orders" then "items" returns the final resource @test

Embedded Resources

  • Accessing embedded data from _embedded.author returns the author object without making an HTTP request @test

Implementation

@generates

API

/**
 * Creates a HAL-aware HTTP client for the given base URL.
 *
 * @param {string} baseUrl - The base URL of the HAL API
 * @returns {Object} Client with methods to fetch and navigate HAL resources
 */
function createHalClient(baseUrl) {}

/**
 * Fetches a HAL+JSON resource from the specified path.
 *
 * @param {string} path - The path to fetch
 * @returns {Promise<Object>} Promise resolving to the HAL resource with entity data
 */
// Method on the client returned from createHalClient
function fetch(path) {}

/**
 * Follows a link relationship from the current resource to a related resource.
 *
 * @param {Object} response - The current HAL response object
 * @param {string} rel - The link relationship name
 * @returns {Promise<Object>} Promise resolving to the related resource
 */
// Method on the client returned from createHalClient
function follow(response, rel) {}

module.exports = { createHalClient };

Dependencies { .dependencies }

rest { .dependency }

Provides RESTful HTTP client with HAL support for hypermedia navigation.

@satisfied-by

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/rest@2.0.x
tile.json