Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Christopher London
    @chrisjl154
    Cheers!
    Jim
    @JimSR
    How would you guys go about documenting example error responses in the following format: https://datatracker.ietf.org/doc/html/rfc7807
    The error response would include the complete path. Which you might not know when setting the meta info using returning()
    Because the contract might be composed at other places.
    To clarify: the actual response formatting is easy using the ErrorResponseRenderer. This is purely about generating / defining correct examples without coupling code.
    Priti
    @pritibiyani
    Hello,

    Is there any way we can access currentRequest in context? eg. In Spring we can access

        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();

    My intend is, I want to have a state for a request.

    Use case is, we want to make application traceable.
    1. Each request creates own unique trace id.
    2. This trace id should be accessible everywhere in application. One approach is pass it whenever needed, but that will make code clutter. Also this is in a way application context and hence we want to make it available in context with current request everywhere.
    3. We can use our own small TraceIdHolder and keep it in that one, but its not safe as another request can modify the state. Hence we need something which is unique and retrived using current request.
    Priti
    @pritibiyani
    For the above use case, can I use @ThreadLocal ? The core aassumption for this one would be each request is served by different thread. Is it safe to use?
    3 replies
    David Denton
    @daviddenton
    Priti
    @pritibiyani
    But then for this to access the context, I would always have to pass request around my application, which is someting I do not want.
    David Denton
    @daviddenton
    And you would be right to not want that. You should only ever access that content from the sane abstraction layer reakky:
    ... (apologies for spelling - afk!)
    ... But its the job of the HTTP layer to solve that problem for the HTTP layer. We'd suggest looking at other solutions for the domain layer (such as those seen in hexagonal architectures)
    2 replies
    David Denton
    @daviddenton
    We always prefer explicit over implicit communication of state - the request contezt route is designed to feel a little clunky for that very purpose! 🙃
    1 reply
    Jakub Janeček
    @jakubjanecek
    Hello. I am trying to persuade my company to start using http4k and it would help me to know what other companies are using http4k and for how big projects. Is that information publicly known?
    David Denton
    @daviddenton

    http4k originated as a project created by the London TDD community. The project started in 2016 and has been steadily gaining popularity ever since.

    Lots of companies are naturally guarded about their tech stacks, but http4k's most high-profile (and public) user is the scientific publisher SpringerNature - where it drives a lot of the content delivery platform for multiple domains, including nature.com which is reported (by RankChart https://rankchart.org/site/springernature.com/) that Alexa ranks at 526 in the world - in case you were wondering about "webscale" :) . Apart from that, we get contacted quite frequently for consulting by companies for lots of different industries, and specifically we do know that it is used by a quite a of global investment and retail banks for various projects.

    The main authors are members of the Kotlin Google Developer Expert community and engage quite frequently with JetBrains, where http4k is listed as one of the top Kotlin frameworks on the JB site: https://kotlinlang.org/lp/server-side/ . The framework is featured in several books about Kotlin, including this excellent one (https://www.oreilly.com/library/view/java-to-kotlin/9781492082262/ )

    David Denton
    @daviddenton
    For me, the "killer app" of http4k is definitely the options and power it gives you around testing.. AFAIK we are the most TDD-driven framework out there - although I'd love to know if we're not so that we can get more ideas about testing ! :)
    Jakub Janeček
    @jakubjanecek
    Thank you for the answer.
    stoco-loco
    @luca-battistelli
    Hello everyone, I am trying to create a http4k ContractRoute where I define the schema for the return type but not an example? Am I right to think that is not possible? receiving has an option for passing only a BiDiBodyLens but returning does not
    Michael Grigoryan
    @michaelgrigoryan25
    Hi everyone! New to http4k and so far I'm really enjoying it! I have a simple question regarding logging. Is there a way to disable the default logger of http4k?
    David Denton
    @daviddenton
    There is no "logger" per-se built into http4k. If you're seeing logging output when starting up a server then it will be coming from whichever backend you're using - so you can refer to the docs of that library to configure the logging. It's worth noting that we recommend using the Structured Logging approach over logging library and levels: https://www.http4k.org/guide/howto/structure_your_logs_with_events/
    Michael Grigoryan
    @michaelgrigoryan25
    I see, thank you! And by any chance, is there a way to disable the logging in a backend? Like with an environment variable or maybe with a CLI argument?
    David Denton
    @daviddenton
    Undoubtably - but you'd have to see the docs for the backend in question. :)
    Michael Grigoryan
    @michaelgrigoryan25
    Got it. Thanks!
    Michael Grigoryan
    @michaelgrigoryan25
    One thing I noticed is that the code of http4k-core is mostly not documented internally(correct me if I'm wrong). When having a peek at a function(or method, etc.) from IntelliJ, most of the functions are not documented. If there's nothing that I'm doing incorrectly I may be able to help document the code internally after grasping the concepts of http4k's core =)
    David Denton
    @daviddenton
    You're right - by default we don't document everything (on purpose) - we kind of hope that most things are obvious enough from the names to work out what is going on. Apart from that, we generally document stuff that we expect people to use and might find useful - for instance the various Filters are generally documented fairly. You'll generally get most value from reading the examples on the site. There are a lot of patterns which are repeated over and over again in the library - and it's more a case of knowing what is available rather than how it works when you find it. Generally you can use a rule of thumb which says if you need it then it's probably something that already exists - we are terribly lazy and tend to add useful things as we come across them.
    For help, the http4k channel on the official Kotlin slack instance is a good place to go for help if you need it.
    Michael Grigoryan
    @michaelgrigoryan25
    Got you, thanks for clarification!
    Ben Green
    @maedjyuk-ghoti
    Hello! I'm primarily an Android developer and It's my first time using http4k or making a backend of any kind. I'm trying to setup oauth and am having a bit of trouble. I've gone through the project wizard and the only meaningful change I've made is to switch OAuth providers from Google to Auth0. Redirecting to the Auth0 login is working but, upon completing login on their end and returning to the callback, I'm met with a 403. Stepping through with a debugger, it looks to be failing to pull the csrfName cookie out of the request. Is there something extra I need to configure to get this working? Thanks in advance.
    John Green
    @johnsgp
    Hello, I'm looking for help with changing the Content-Type header of the response in the Swagger docs to refer to JsonApi (https://jsonapi.org/format), using http4k-contract. I have an example at https://github.com/johnsgp/http4k-contract-example where it is not working. Presumably, I've done it incorrectly in App.kt at https://github.com/johnsgp/http4k-contract-example/blob/main/src/main/kotlin/App.kt#L21. I'm asking the question here as recommended in the Contributors' Guide but I can create a GitHub Issue if preferred.
    David Denton
    @daviddenton
    It won't automatically return the content type set in the meta if that's what you're after - that is just for the docs. you can if you want create a custom Jackson instance which returns that content type always
    open class ConfigurableJackson(val mapper: ObjectMapper,
                                   val defaultContentType: ContentType = APPLICATION_JSON) : AutoMarshallingJson<JsonNode>() {
    `
    John Green
    @johnsgp
    I'm trying to get it in the docs. It's OK when I make the API call.
    I tried a ConfigurableJackson, but the response Content-Type disappears altogether when I do that (possibly incorrectly too).
    John Green
    @johnsgp
    image.png
    I just noticed I left out one commit, which I've pushed. This is what I see in my browser tabs -- have I somehow broken the contract and not triggered a warning?
    David Denton
    @daviddenton
    TBH - at first glance looks like there may something in the APIRenderer which is using the JSON content type by default
    but this line should not exist: val responseBody = Jackson.autoBody<ResponseData>().toLens()
    because it's using the default content type in the default jackson implementation
    John Green
    @johnsgp
    Thanks @daviddenton
    David Denton
    @daviddenton
    @johnsgp I;ve confirmed that it works for responses: "responses": { "200": { "description": "OK", "content": { "application/yaml": { "example": { "anotherString": "bar" }, "schema": { "$ref": "#/components/schemas/ArbObject4", "example": null, "description": null } } } } }
    if you use.. Body.auto<ArbObject4>(contentType = APPLICATION_YAML).toLens()
    John Green
    @johnsgp
    @daviddenton , thanks, you've just helped me to confirm that it's broken in the version I was using - 4.7.1.0 - but works in the latest - 4.19.0.0 :star2:
    jcaraballo
    @jcaraballo
    Hi all! We've got a web form with an optional field which we parse as Int. val percentageField = FormField.string().map{it.ifBlank { null }?.toInt()}.optional("percentage") seems to do the trick but I wonder whether there's something better available to make optional interpret blank as missing?
    David Denton
    @daviddenton
    not really TBH. but you can make an extension method on FormField<WebForm, String?> to make it neater.. :)
    jcaraballo
    @jcaraballo
    Thank you! I tried that but I stopped when I bumped into set being internal... Maybe I didn't try hard enough O:-)
    David Denton
    @daviddenton
    you can just do it as a map
    Anton Gorev
    @kvirund

    Hi,

    I am trying to create a WebsockerClient like this:

    val client = WebsocketClient.blocking(Uri.of("ws://localhost:1212/"))

    but if a server is unavailable, I am getting the exception

    Exception in thread "WebSocketConnectReadThread-17" java.net.ConnectException: Connection refused (Connection refused)
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:476)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:218)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:200)
        at java.net.Socket.connect(Socket.java:606)
        at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:473)
        at java.lang.Thread.run(Thread.java:748)

    and control never returns to my application.

    So, the question is how am I supposed to handle such kind of exception?

    Thanks

    5 replies