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-10/

API Response Inspector

Build a utility that inspects HTTP API responses and extracts specific information. The utility should provide convenience methods to examine different aspects of API responses without requiring users to handle complete response objects.

@generates

Capabilities

Extract Response Body

  • Returns only the response body/entity when inspecting a successful API response @test
  • Returns only the response body/entity when inspecting an error response @test

Extract Status Information

  • Returns only the status code when checking the response status @test
  • Correctly identifies successful status codes (2xx range) @test

Extract Header Information

  • Returns all response headers as an object @test
  • Returns the value of a specific header by name @test
  • Returns the Content-Type header value @test

Requirements

Implement the following functions:

  1. getResponseBody(url) - Makes a request to the given URL and returns a promise that resolves to only the response body
  2. getStatusCode(url) - Makes a request to the given URL and returns a promise that resolves to only the status code
  3. getAllHeaders(url) - Makes a request to the given URL and returns a promise that resolves to all response headers
  4. getHeader(url, headerName) - Makes a request to the given URL and returns a promise that resolves to the value of the specified header
  5. checkContentType(url) - Makes a request to the given URL and returns a promise that resolves to the Content-Type header value

All functions should handle both successful and error responses appropriately.

API

/**
 * Get only the response body from an HTTP request
 * @param {string} url - The URL to request
 * @returns {Promise<any>} Promise resolving to response body
 */
function getResponseBody(url) {
  // IMPLEMENTATION HERE
}

/**
 * Get only the status code from an HTTP request
 * @param {string} url - The URL to request
 * @returns {Promise<number>} Promise resolving to status code
 */
function getStatusCode(url) {
  // IMPLEMENTATION HERE
}

/**
 * Get all response headers from an HTTP request
 * @param {string} url - The URL to request
 * @returns {Promise<object>} Promise resolving to headers object
 */
function getAllHeaders(url) {
  // IMPLEMENTATION HERE
}

/**
 * Get a specific response header from an HTTP request
 * @param {string} url - The URL to request
 * @param {string} headerName - The name of the header to retrieve
 * @returns {Promise<string>} Promise resolving to header value
 */
function getHeader(url, headerName) {
  // IMPLEMENTATION HERE
}

/**
 * Get the Content-Type header from an HTTP request
 * @param {string} url - The URL to request
 * @returns {Promise<string>} Promise resolving to Content-Type value
 */
function checkContentType(url) {
  // IMPLEMENTATION HERE
}

module.exports = {
  getResponseBody,
  getStatusCode,
  getAllHeaders,
  getHeader,
  checkContentType
};

Dependencies { .dependencies }

rest { .dependency }

Provides HTTP client capabilities for making requests.

Version

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