Ktor vs http4k

Поділитися
Вставка
  • Опубліковано 7 лис 2024

КОМЕНТАРІ • 33

  • @PairingWithDuncan
    @PairingWithDuncan  6 місяців тому +9

    I realised in the edit that I didn’t stress how wonderful the symmetry in http4k is, and how I miss that in other frameworks. The fact that the client and server both work with the same Request and Response and HttpHandler and Filter is freeing. I’ll look at this next episode.

    • @garethrowlands
      @garethrowlands 2 місяці тому +1

      That aspect of http4k is indeed a joy!

  • @FeeshNL
    @FeeshNL 6 місяців тому +5

    I love that Intellij had the exact same response to you including a hyphen in a filename as me.
    Great video, I've been meaning to try http4k and seeing the comparison has been very useful.

    • @PairingWithDuncan
      @PairingWithDuncan  6 місяців тому +4

      I’m in the habit of using lower-case file names for collections of functions: saving.kt, printing.kt etc, and I think dashes in filenames are just easier to type and read in these cases. But we all have different tastes.

    • @PairingWithDuncan
      @PairingWithDuncan  6 місяців тому +2

      It’s good to know that it’s useful material, so thank you. I am biased, having worked in the group that created http4k, but I truly rate it as a world-class piece library.

    • @FeeshNL
      @FeeshNL 6 місяців тому +1

      @@PairingWithDuncan I've never considered it, I'm a camelcase kind of person though. Only poking fun though, genuinely great content, looking forward to seeing more.

  • @Jallallalla
    @Jallallalla 5 місяців тому

    I keep seeing this nice green test bar in all your videos. I want it! Can you tell me the name of the plugin?

    • @PairingWithDuncan
      @PairingWithDuncan  5 місяців тому

      It's available free for premium subscribers!
      Or you can install the initimatble @dmitrykandalov's liveplugin plugins.jetbrains.com/plugin/7282-liveplugin and then this gist gist.github.com/dmcg/1f56ac398ef033c6b62c82824a15894b

  • @Aayar22
    @Aayar22 6 місяців тому +4

    I have seen that there are very less views on your video but still, you are making it for a very long time how do you get motivation for that.

    • @lkyuvsad
      @lkyuvsad 6 місяців тому +8

      6000 people a month considering your opinions is better than most of us achieve in a whole career. Seems pretty motivating.

    • @PairingWithDuncan
      @PairingWithDuncan  6 місяців тому +7

      This one is very new, but UA-cam says it is the second most popular of the last 10 - I’m seeing a steady growth in views and subscribers over the months. Which is nice, as is the feedback and thanks that i get from people here and in real life.

  • @guai9632
    @guai9632 5 місяців тому +1

    ktor looks less magical, which is a good thing

    • @PairingWithDuncan
      @PairingWithDuncan  5 місяців тому +1

      Interesting, thank you! Personally I find http4k less magical than Ktor, which is a lot less magical than Spring. I suppose that magic is a question of perspective, of what tricks we have seen before or know how they are done.

    • @garethrowlands
      @garethrowlands 2 місяці тому

      kttp4k looks less magical to me than ktor, being made largely from plain functions. But, then again, there's real magic in what functions can do.

  • @DavidA-fi9jy
    @DavidA-fi9jy 6 місяців тому +3

    It seems like the main thing that was bothering you was Ktor's mutating routing at each step... but if you look at the DSL as a type of builder, which it is since most of this code is running at startup, then it might not be so bad. And you gain the fact you can run coroutines libraries... I'm sure there's a more generic form instead of post(...)... etc that gets the type of request, so that might not be an issue if you want to have the same handler for multiple route types, and anyways, you could always pass a lambda you saved in a val before in multiple routes.

    • @PairingWithDuncan
      @PairingWithDuncan  6 місяців тому +4

      It’s certainly true that undetectable mutation during initialisation isn’t an issue, but I do find it interesting that one api requires a context during configuration and the other doesn’t.

    • @PairingWithDuncan
      @PairingWithDuncan  6 місяців тому +4

      I suppose that I’ve started from the examples provided by the documentation to get a feel for the way that the authors think. Ktor is DSL-based; http4k is building functions with functions. In Ktor it would be difficult to configure serialisation on a handler-by-handler basis; in http4k we have to specify the serialisation in each handler. There are pros and cons to each, I suppose I might characterise the feel as Ktor is more out-of-the-box framework; http4k more blocks that can be composed.

    • @PairingWithDuncan
      @PairingWithDuncan  6 місяців тому +3

      Ultimately I think coroutines will prove to be an irritation not a benefit for server-side JVM developers who can use Loom. I may be proved wrong!

    • @DavidA-fi9jy
      @DavidA-fi9jy 6 місяців тому +2

      @@PairingWithDuncan Given the amount of libraries currently supporting coroutines and it's KMP support, I don't think it's being replaced by loom in the near future, and the simplicity of handling concurrency with it is great! You just write what looks like imperative code and the concurrency is mostly handled for you... and Flows don't have a Loom replacement for now (maybe RxJava or the likes will/do support it? -- but their complexity compared to Flow is a big disadvantage...)

    • @DavidA-fi9jy
      @DavidA-fi9jy 6 місяців тому +2

      @@PairingWithDuncan I'm not saying I don't like Http4k's composable block approach -- I'm just saying that Ktor's approach isn't really some mutable monster that could explode on you... it's just a builder DSL that also uses functions to handle requests - but instead of (Request) -> Response, you have a context that you get the request from and call functions from it to return a response, which is a better model for concurrency inside that lambda... you don't wait for a response to return from the lambda with it - so you can do a bunch of concurrent stuff beyond the lifetime of the lambda as long as you call the respond function on the context to return a response. And the lifetime of the lambda is, I suppose, the "threads/coroutines" pool that handle the requests that are incoming and should not be blocked... in Http4k, you'd have to open a new virtual thread to run the lambda and get the response without blocking the pool that receives the incoming requests.