from Hacker News

Show HN: Tokamak – Server-side framework for Zig

by cztomsik on 2/5/24, 10:58 AM with 26 comments

  • by latch on 2/7/24, 5:38 AM

    As a Zig developer with one of the more popular HTTP server libraries around (http.zig), this is impressive and good use of comptime and (good) abuse of Zig's anytype. I'm looking forward to learning from the codebase.

    But, it's very slow. A quick test shows Sinatra is about 2x faster. Maybe I'm in the minority, but I feel that a primary reason to give up a GC is for performance.

  • by ngrilly on 2/7/24, 9:15 AM

    Putting the HTTP method and path directly in the function's name using Zig @-syntax is something I've never seen before. Clever.
  • by twarge on 2/7/24, 2:44 AM

    the name tokamak - funny choice! Will barely achieve fusion with an huge and complex implementation. Surely not the intended implicature.
  • by mbStavola on 2/6/24, 7:24 AM

    I'm not a Zig programmer, but this framework seems pretty nice! Honestly, a lot nicer than I would've expected from a language that explicitly targets lower-level dev[1].

    [1]: Rust also has a focus on low-level programming, but has many higher level constructs / a more complicated type system so I'm not too surprised when I see nice web frameworks in that ecosystem

  • by clebert on 2/7/24, 12:59 PM

    I love the use of `@hasDecl(root, "mime_types")`. I didn't realize that `@import("root")` was a thing.

    https://github.com/cztomsik/tokamak/blob/main/src/mime.zig

  • by apitman on 2/7/24, 5:47 AM

    Interesting. What mechanism does Zig use to hook up function argument dynamically depending on what is declared in the function (or am I reading that wrong)? Not sure I've ever seen something quite like it.
  • by jedisct1 on 2/5/24, 11:47 AM

    Looks great! Also TIL about AVA https://github.com/cztomsik/ava
  • by myko on 2/7/24, 2:49 AM