Skip to content

lsd-consulting/lsd-interceptors-http4k

Repository files navigation

semantic-release

lsd-interceptors-http4k

Build Nightly Build GitHub release Maven Central

Provides a Http4k Filter for intercepting http requests and responses and adding the details to the provided lsdContext instance.


Usage

  • Add dependencies
    implementation 'io.github.lsd-consulting:lsd-core:<version>'
    implementation 'io.github.lsd-consulting:lsd-interceptors-http4k:<version>'
  • Configure an interceptor with an LsdContext
    // Obtain an instance of an LsdContext 
    private val lsd = LsdContext.instance

    // Pass the lsdContext instance to the filter provider (along with any additional options)
    private val lsdFilter = LsdFilterProvider(lsd).filter
  • Include the filter in the filter chain for your application handler e.g.
    val app = lsdFilter.then(appHandler)
  • Invoke your application with requests, e.g. via tests

    • By default User-Agent header is used to determine the source participant name
    • By default Host header is used to determine the target participant name
    • You can override these when instantiating the LsdFilterProvider class by overriding the sourceNameProvider or targetNameProvider to use alternative headers or anything else available in the Request
  • Generate the report:

// You can capture multiple scenarios within a report
lsd.completeScenario("scenario title")

// Finally created the report
lsd.completeReport("report title")

For a contrived example, see file ExampleWithReportGenerated.kt which was used to generate the below report. Each arrow can be clicked to reveal the headers and body of each request and response:

example.png


See lsd-core project for further details on how the reports with sequence diagrams can be generated.