https://kotlinlang.org logo
Join SlackCommunities
Powered by
# http4k
  • a

    Andrew O'Hara

    02/20/2025, 6:11 PM
    Upon upgrading http4k to v6, I've noticed that with
    RequestContextKeys
    being replacing by
    RequestKeys
    ,I no longer need to pass around a shared context and initialize the server filter stack with the context. Super happy with that!
    🙂 1
    d
    l
    +2
    • 5
    • 15
  • g

    Gopal S Akshintala

    02/24/2025, 7:17 AM
    Hi Team, raised a small pull request for a bug fix. Can someone please take a look: Add `lenient()` for adapter for Lenient strictness in ConfigurableMoshi by overfullstack · Pull Request #1299 · http4k/http4k This change should help in parsing JSON in lenient format (leninet mode as stated here in Moshi: [JsonReader.kt](https://github.com/square/moshi/blob/256b13b3bfd6cb5557c857496e674b0b1ab98d10/moshi/src/main/java/com/squareup/moshi/JsonReader.kt#L200-L200)), as per the lenient param in the ConfigurableMoshi constructor.
  • j

    Jordan Terrell

    02/25/2025, 9:31 PM
    Hello! Is there a way to add custom HTTP headers to the 101 Switching Protocols response when responding to a Websocket connection request in http4k?
    d
    a
    • 3
    • 3
  • d

    DanielZ

    03/03/2025, 1:19 PM
    Hey, we are in the migration phase from OpenTelemetry 1.x to 2.x (I know we’re slow 🥱 ) Is someone already actively working on https://github.com/http4k/http4k/issues/943 or does it make sense to have a look at this? Not promising anything 🤗
    s
    d
    • 3
    • 6
  • d

    DanielZ

    03/04/2025, 10:36 AM
    Hey, When I try to update from version
    6.0.1.0
    to
    6.1.0.0
    I run into
    java.lang.IllegalStateException: Request was not routed, so no uri-template present
    . What I’m doing wrong here?
    Copy code
    class AppHttpFilterShould {
        @Test
        fun `extract customer id for logging`() {
            var receivedRequest = Request(GET, "")
            val app = routes(
                "/v1/customer/{id}" bind GET to { receivedRequest = it; Response(OK) },
                "/v1/customer/{other-id}/{x}" bind GET to { receivedRequest = it; Response(OK) },
            )
            val request = Request(GET, "/v1/customer/407")
    
            app(request)
    
            receivedRequest.identifier() shouldBe Identifier.CustomerId("407")
        }
    }
    
    sealed interface Identifier {
        data class CustomerId(val id: String) : Identifier
        data class CompanyId(val id: String, val x: String) : Identifier
        data object NoId : Identifier
    }
    
    fun Request.identifier(): Identifier {
        val id = path("id").orEmpty()
        val otherId = path("other-id").orEmpty()
        val x = path("x").orEmpty()
        return when {
            id.isNotBlank() -> Identifier.CustomerId(id)
            otherId.isNotBlank() -> Identifier.CompanyId(otherId, x)
            else -> Identifier.NoId
        }
    }
    d
    s
    • 3
    • 2
  • m

    Martin Smiech

    03/10/2025, 2:54 PM
    Hello, does anyone know whether S3Bucket.copyObject should support UTF-8? AWS itself does. When I try to use it with a source/destination bucket containing a UTF-8 char, it throws an IllegalArgumentException: Unexpected char (e.g. char 0x301, U+0301).
    🤔 1
    a
    d
    • 3
    • 15
  • a

    Andrew O'Hara

    03/13/2025, 4:51 PM
    🚀 New video incoming! 🚀 This one is targeted at beginners with live coding.

    https://www.youtube.com/watch?v=nHVeMEbZYKI▾

    👯‍♂️ 1
    http4k 2
    🚀 1
  • d

    dave

    03/14/2025, 5:18 PM
    🎉 Launch Announcement: http4k MCP Desktop Client 🎉 Just in time for the weekend - we're excited to announce the launch of the http4k MCP Desktop Client, which allows you to interface desktop LLM runners such as Claude Desktop with remote MCP servers running locally or in the cloud. Key Features: • Multi-protocol: As well as the standard SSE protocol, we have extended the MCP specification with additional transports (WebSocket, JSON-RPC) • Run MCPs in stateless mode (JSON-RPC) for distributed Cloud and Serverless environments. • Extended HTTP authentication (API Key, Bearer Token, Basic Auth, OAuth). Note that until the next version, the MCP spec currently does not specify security models, but these options will allow you to use existing community MCP servers which do require auth. • Simple installation - with our binary distribution - so no messing around with NPX to get running. And if you install with
    brew
    then Claude will automatically have access to the binary. The client is specially optimised for servers built with the http4k MCP SDK which is being released in the very near future. With the SDK, you'll be able to build MCP servers as simply as you build HTTP applications with http4k: Clean + Simple + Functional + Testable. 🙃 Check out the full documentation and download options at: https://github.com/http4k/http4k-mcp-desktop Stay tuned for the http4k MCP SDK release coming soon ! Happy weekend! 🦜
    http4k 2
  • d

    dave

    03/17/2025, 4:27 PM
    For anyone in (or near to!) London, it turns out that April is a fairly great month for Kotlin meetups. Join us near Bank Station on the 17th for an http4k double header... @s4nchez: Full Stream Ahead: Breaking the protocol barrier with http4k (KotlinConf preview) http4k models realtime WebSocket and Server-Sent Events as simple, testable functions, extending HTTP's capabilities while maintaining developer experience. This approach reimagines frontend development by moving reactive capabilities to the server, enabling modern interfaces without client-side complexity. These streaming features have the ability to bring web development full circle, delivering real-time experiences with the complexity managed exactly where it belongs - on the server. We'll take you on a tour of the protocols, APIs and how you can use them to transform your approach to building interactive web applications. @dave (that's me!) : Functional Intelligence: Agents, MCP and the end of the Web(?) We spend countless hours navigating poorly designed interfaces and completing tedious digital tasks that consume our time rather than serve us. The Model Context Protocol (MCP) offers a path to liberation by enabling AI agents to interact directly with services on our behalf, fundamentally reshaping the human web experience. This talk will demonstrate how http4k's new MCP SDK brings this future closer with its functional, zero-magic approach—showing how tasks that once required multiple manual steps can be automated through agentic interfaces built with just a few simple functions. https://www.meetup.com/source-talks-on-kotlin/events/306722368/?eventOrigin=home_page_upcoming_events%24all
    K 2
    🎉 1
  • m

    MrNiamh

    03/24/2025, 8:45 AM
    👋 hello hello. I'm having some trouble with a recursive class and generating the openapi definition. I have something like the below example:
    Copy code
    data class FieldDTO(
        val name: String,
        val obj: ObjectField,
    ){
        companion object {
            val example = FieldDTO(
                name = "Field",
                obj = ObjectField.example
            )
        }
    }
    
    data class ObjectField(
        val name: String,
        val field: FieldDTO? = null,
    ){
        companion object {
            val example = ObjectField("obj", field = FieldDTO.example)
        }
    }
    The compiler obviously throws an error on the
    ObjectField
    example, but if I set the example to be
    ObjectField("obj", field = null)
    then I get an issue with
    NoFieldFound
    on generating the openapi as it doesn't like having nulls. Tried to have a search but couldn't find much on what the best approach here is!
    a
    • 2
    • 4
  • a

    Arnab

    03/27/2025, 10:48 AM
    I was thinking of adding some functionality to the http4k-config package, specifically regarding optional files:
    Copy code
    /**
             * Load configuration from optional Properties file format on disk
             */
            fun fromOptionalFile(file: File): Environment = if (file.exists()) from(file) else EMPTY
    Should I just submit a PR and explain my usecase or would you like me to create an issue first? This is a very simple change that has like 5-6 lines total of code (including tests)
    a
    j
    • 3
    • 4
  • a

    Andrew O'Hara

    03/28/2025, 12:19 PM
    In this episode, I show how you can secure your Http4k API by verifying JWTs from a Social Login Provider, like Google or Facebook. APIs don't typically host the login flow, but I've included a rudimentary login page to get your token.

    https://youtu.be/tabgrddX6VA▾

    http4k 2
    🦜 1
    K 1
  • d

    dave

    03/28/2025, 5:51 PM
    It's here! 🚀 Hot on the heels of the latest MCP specification—which we helped shape—we're proud to launch the first released JVM implementation of the http4k Model Context Protocol (MCP) SDK. Team #C5AL3AKUY involved in the discussions around evolving the MCP specification, contributing our expertise and insights to the open standard. Now, that spec is Gold, we're bringing those insights to life with an SDK that: 🌐 Delivers stateless HTTP MCP connections ☁️ Supports Server and Serverless deployments across on-prem and cloud platforms 🛡️ Maintains rock-solid testability that http4k is known for 🔒 Provides type-safe tooling 🔀 Switch protocols with 1 Line of Code . Maintains compatibility with the new and legacy transport versions. Key highlights: - First VM-based SDK for the new MCP spec - Native support for stateless AI interactions - Zero-compromise approach to testing AI integrations - Serverless deployment ready (AWS Lambda, GCP Functions) - Easy desktop integration with AI assistants like Claude Download it, have a play and come and tell us what you think! 🙃 https://www.http4k.org/news/http4k_mcp_has_landed/
    🎉 4
    🆒 3
    g
    • 2
    • 8
  • a

    Andrew O'Hara

    03/30/2025, 3:03 AM
    So, I frequently need to have servers within a cluster talk to each other. For example, a cluster that holds websockets, and exposes a control API. Rather than have clients of the control API figure out which server is holding the websocket, I want them to use the load balancer. But to make that work, any server in the cluster that gets the request needs to be able to figure out which server holds the websocket, and then find a way to send the command to it. In the past, I've been able to take advantage of the fact that each server is running on an instance, with an accessible private IP: • Use the aws load balancing API to get the private IPs of each server in the target group • each server publishes their active websockets to a table, including their private IP • each server publishes their private IPs to a table, and you poll them for the websocket But I now have a similar service that's running in ECS/K8s, and there's no (easy) way to access each server individually. • I can't use AWS SQS, because there's no way for servers to subscribe to just the messages intended for them (and no way to send messages to all servers) • I don't really want to use AWS SNS, because each server would have to dynamically create/subscribe/unsubscribe an SQS queue for themselves • MQTT is annoying to set up, and I don't have an incredibly robust fake for it yet So, I thought about using redis as a message broker. But realized I not only wanted to send the commands, but ensure they're processed correctly. So I came up with the idea for Http4k over Redis! This will let you map commands and acknowledgements to the http4k workflow we're all accustomed to. It seems to work in my tests, but I have no idea if it will stand up to production use. Will try to integrate on Monday. Thoughts are welcome. https://github.com/oharaandrew314/http4k-over-redis
    http4k 2
  • a

    Andrew O'Hara

    03/31/2025, 7:15 PM
    Why does
    ResourceLoadingHandler.loadPath()
    filter out requests for octet streams? I'm trying to host an HLS stream, but the
    static
    server is returning 404s for every binary segment after the text playlist.
    • 1
    • 1
  • a

    Andrew O'Hara

    04/02/2025, 2:20 PM
    Here's a guide on getting OpenAPI and Swagger UI available in your http4k app.

    https://youtu.be/OsTrVe4LQtY▾

    http4k 4
  • a

    Andrew O'Hara

    04/05/2025, 5:52 PM
    I was under the impression the
    JavaHttpClient
    was perfectly fine for production. Is this no longer the case?
    d
    m
    • 3
    • 2
  • l

    leonhardt

    04/07/2025, 6:03 AM
    Is
    http4k-connect-storage-s3
    intended to be a provider agnostic S3 adapter, or just for AWS? I was lured into trying it with GCP's cloud storage because "AWS" isn't in the package name, but I'm finding the interface has lots of AWS specifics like: • the CredentialsProvider interface is expected to return an AwsCredentials object • region is an enum from org.http4k.connect.amazon.core.model
    d
    • 2
    • 2
  • a

    Andrew O'Hara

    04/09/2025, 3:40 PM
    Learn how Http4k's client-server symmetry reuses your existing knowledge, and simplifies testing. This will likely be the last episode of the series that will cover Http4k directly; next will be packaging and deployment!

    https://youtu.be/junAVAR0pT0?si=NVT2KKh3kCkzP_Yx▾

    http4k 3
  • j

    Jonathan Hult

    04/10/2025, 2:51 PM
    Would it be possible to make
    org.http4k:http4k-security-oauth
    "pluggable" with other JSON formatters instead of relying directly directly on
    http4k-format-moshi
    ?
    d
    a
    • 3
    • 10
  • l

    leonhardt

    04/11/2025, 6:44 AM
    Inspired by one of @Andrew O'Hara's recent videos, I'm exploring the
    http4k-api-openapi
    module. When using a path lens, I've got a route working when the lens is at the end of a route, but I'm stuck on how to place one in the middle of a route. Any tips?
    ❤️ 1
    d
    a
    • 3
    • 7
  • a

    arne.stockmans

    04/11/2025, 9:12 AM
    Hi all, I’m doing some heavy work on one of my endpoints. Is there an easy way to already return a Response, and do the work afterwards?
    d
    a
    c
    • 4
    • 7
  • t

    Tim Mortimer

    04/12/2025, 9:29 AM
    This is a bit scrappy, but I've been experimenting with adding an http4k idempotency filter based on the following standard: https://datatracker.ietf.org/doc/draft-ietf-httpapi-idempotency-key-header/ My current sketch is by no means worthy of a PR, and would require significant rework to make it sufficiently flexible, but the attached snippet is what I've got so far. Out of interest, has anyone considered a similar sort of mechanism before? If so, how did you go about implementing it? Would you find this useful in your own projects?
    idempotency.kt
    d
    j
    • 3
    • 5
  • g

    Gopal S Akshintala

    04/17/2025, 10:57 AM
    How can I accept a list of strings with
    Tool.Arg
    ? I am not able to find something like a
    list()
    method?
    Copy code
    val pathsArg =
      Tool.Arg.string().required("collectionPath", "List of Absolute paths")
    I want Cursor to call my MCP with argument like this:
    Copy code
    {
      "paths": [
        "../..",
        "/.."
      ]
    }
    d
    • 2
    • 14
  • l

    leonhardt

    04/27/2025, 11:13 PM
    Is there any trick for how to create an empty RoutingHttpHandler? When I try to anything like
    routes(emptyList())
    I get:
    Exception in thread "main" java.lang.IllegalArgumentException: No routes added!
    at org.http4k.routing.RoutingHandler.<init>(RoutingHandler.kt:19)
    at org.http4k.routing.RoutingHttpHandler.<init>(http.kt:23)
    j
    d
    • 3
    • 9
  • c

    Cies

    04/28/2025, 12:10 AM
    What serialization lib is most popular with you all: kotlinx, moshi, kotshi, jackson, or <some other lib>?
    d
    n
    • 3
    • 3
  • e

    Emily

    05/04/2025, 9:33 AM
    Is there a preferred way to handle a mutable collection of routes (in this case a map)? This is my initial solution but I feel like there may be a cleaner solution that I've overlooked.
    mutableSample.kt.cpp
    j
    • 2
    • 4
  • a

    Arnab

    05/08/2025, 8:32 AM
    Let's say I have a backend server written in http4k. In addition to my API, I want to offer clients a Kotlin SDK. How would I go about doing this? Is it possible to just create some kind of client based on the functions that I use in the server directly? Does anyone have experience doing this? What would the folder structure look like? Or better yet, does anyone have an example of this that I can take a look at and learn from?
    d
    j
    a
    • 4
    • 9
  • e

    Emily

    05/09/2025, 1:49 PM
    DatastarFragmentRenderer strips newlines from templates with
    String.replace("\n", "")
    . This silently breaks with template files using CRLF. A simple solution could be to change it to
    String.replace("\r\n", "").replace("\n", "")
    .
    d
    • 2
    • 1
  • d

    dave

    05/09/2025, 4:44 PM
    Hi http4k fans! Happy weekend! We've got an update on the #C5AL3AKUY MCP SDK. 🚀 With all the various news around about new MCP attack vectors (Tool Poisoning, DNS rebind attacks, malicious Chrome extensions), we decided to prioritise our efforts to make the http4k SDK as secure-by-default as possible. Read about what we've been thinking (and releasing!). (And be sure get in touch if your team needs a guiding hand in producing MCPs on the JVM platforms with enterprise grade testability, observability and security. 🙃) Finally, we have a big surprise coming up soon around this space... we're busy working on it and will be dropping a bit of a preview next week! https://www.http4k.org/news/simplifying-mcp/
    http4k 2