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

HTTP Request Logger

Build a reusable HTTP request logging system that tracks request and response metadata for API calls.

Requirements

Your task is to create a logging utility that:

  1. Captures and logs request information (HTTP method, path, timestamp) when a request is initiated
  2. Captures and logs response information (status code, request duration) when a response is received
  3. Stores log entries in a configurable way (either to an array or to console)
  4. Works as a wrapper around HTTP client requests

The logger should integrate with the HTTP request/response lifecycle and collect data at both the request phase (before sending) and response phase (after receiving).

Implementation

@generates

Test Cases

  • When a GET request is made to "/users", the logger captures the method "GET" and path "/users" before the request completes @test
  • When a POST request to "/posts" returns status 201, the logger captures the status code 201 @test
  • When multiple requests are made, each request's logs are kept separate and in order @test
  • The logger can be configured to write to different outputs (console vs array) @test

API

/**
 * Creates a request logger that captures request and response metadata.
 *
 * @param {Object} config - Configuration options
 * @param {Array} [config.logs] - Optional array to store log entries for testing
 * @returns {Function} A function that can wrap HTTP requests
 */
function createRequestLogger(config) {
  // IMPLEMENTATION HERE
}

module.exports = {
  createRequestLogger
};

Dependencies { .dependencies }

rest { .dependency }

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

Version

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