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

HTTP Request Logger

Build a configurable HTTP request logging system that tracks request metadata and response information.

Requirements

Create a Node.js module that implements request logging functionality for HTTP requests. The system should:

  1. Log request details including:

    • HTTP method
    • Request path/URL
    • Timestamp when the request starts
    • Request headers
  2. Log response details including:

    • HTTP status code
    • Response time (duration in milliseconds)
    • Response headers
  3. Support configuration options:

    • logRequests: boolean flag to enable/disable request logging (default: true)
    • logResponses: boolean flag to enable/disable response logging (default: true)
    • logger: custom logging function (default: console.log)
  4. Implement proper composition so that logging functionality can be:

    • Added to an HTTP client in a modular way
    • Combined with other functionality (e.g., authentication, error handling)
    • Configured independently for different parts of the application

Test Cases

  • When request logging is enabled, all request details are logged before the request is sent @test
  • When response logging is enabled, all response details including duration are logged after the response is received @test
  • When request logging is disabled via configuration, no request details are logged @test
  • Multiple logging configurations can be composed with other request handlers without interference @test

Implementation

@generates

API

/**
 * Creates a logging wrapper for HTTP requests
 * @param {Object} config - Configuration options
 * @param {boolean} [config.logRequests=true] - Enable request logging
 * @param {boolean} [config.logResponses=true] - Enable response logging
 * @param {Function} [config.logger=console.log] - Custom logging function
 * @returns {Function} A function that wraps an HTTP client with logging
 */
function createLogger(config) {
  // IMPLEMENTATION HERE
}

module.exports = createLogger;

Dependencies { .dependencies }

rest { .dependency }

Provides RESTful HTTP client support with composable interceptor architecture.

Version

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