Building an HTTP Server with Zig, Zap, and Postgres - My thoughts and a code walkthrough

  Рет қаралды 2,110

Code With Cypert

Code With Cypert

Күн бұрын

Пікірлер: 41
@CodeWithCypert
@CodeWithCypert Күн бұрын
So many people suggested http.zig based on what I liked and didn’t like about Zap and Zinc and I’m going to just refactor this project to that as a comparison. I’m not sure how but http.zig by KarlSeguin slipped under my radar, but it’s almost exactly what I’m looking for (or at least, from the readmes). I’ll probably toss the controller approach with that refactor, too.
@_xentropy
@_xentropy 2 күн бұрын
This is quickly becoming one of my favorite channels. Thanks for the Zig content.
@CodeWithCypert
@CodeWithCypert 2 күн бұрын
You trying to make me cry? Because this is how you make me cry. 🥹
@matthieu875
@matthieu875 2 күн бұрын
i was learning rust for the last 3 months before that elixir i think i found my next shiny language lol, if you continue with zig content i hope ur channel will grow cause there isn't a lot on ytb and the language is getting a lot of traction recently with ghostty and primetime speaking about it
@CodeWithCypert
@CodeWithCypert 2 күн бұрын
Ghostty looks so nice! I plan on trying it out soon! I was shocked to hear Prime talk about leaving Rust for Zig or Go, but it seems like he's been working with Jia (?) lately instead?
@matthieu875
@matthieu875 Күн бұрын
​@@CodeWithCypert ghossty is cool but i prefer wezterm this one is in rust and it's really easy to customize cause there is only one config file in lua
@CodeWithCypert
@CodeWithCypert Күн бұрын
That sounds nice! I used Alacritty for a while but swapped back to iTerm, however, I’ve been using Ghostty all day to try it out and I’m already sold on it!
@romangeneral23
@romangeneral23 2 күн бұрын
Thanks for another excellent zig video.
@CodeWithCypert
@CodeWithCypert 2 күн бұрын
Thank YOU for watching and participating in discussions! I’m glad you enjoyed the video!
@romangeneral23
@romangeneral23 Күн бұрын
@@CodeWithCypert Quick question: Is there a standard that you followed to make the web server ? It is projects like this that can really make one understand and learn a language.
@CodeWithCypert
@CodeWithCypert Күн бұрын
@romangeneral23 can you clarify what you mean by standard? My thought process was this: “people have asked for HTTP server APIs in Zig, specifically with Zap. I build API servers all the time, just not in Zig. So let’s take what I know about servers in Go and TypeScript and find a minimal project to focus on the core competencies for this idea. Something simple - Postgres table with a single column, if you can add one column, you can add twenty. Same with the idea of a controller, if you learn how to make and register one, you’ll be able to do it again and again.” That boiled down to a single controller with a single table backing it, and keeping the data structure simple so I’m not bogged down in other things and can just focus on handling requests, dispatching handlers, parsing json, and executing queries. Hope that helps!
@romangeneral23
@romangeneral23 Күн бұрын
@@CodeWithCypert Many centuries ago I wrote an HTTP server in C for my college final project. It involved sockets, memory management, etc. That's sorta where I am going with.
@CodeWithCypert
@CodeWithCypert Күн бұрын
Ah, I see. Generally I’ll try to use the highest level tools available to solve my needs, but not something that over-abstracts on my needs. For example, in Python, I would choose Flask for this project over something bigger like Django.
@marius.ileana
@marius.ileana Күн бұрын
Reposting again (seems that my initial comment disappeared): First of all, thanks (again) for the sample, Brad! The problem with the potential memory leaks is that you called `_ = gpa.detectLeaks();` at the end of the `main` function. And that is executed before the `defer pool.init()`. That's why it will always complain about memory leaks, even if you just comment out all the other lines after your `defer pool.deinit()`. So, you can use `defer _ = gpa.detectLeaks()` right after the `gpa` variable initialization.
@CodeWithCypert
@CodeWithCypert Күн бұрын
Oh my gosh. What a silly mistake. Thank you for reposting, I’m not sure what happened with your comment. I went to find it and couldn’t. Lemme make sure KZbin didn’t hold your original for review, and thanks for helping highlight that issue.
@chrishabgood8900
@chrishabgood8900 Күн бұрын
microsecond response time SWEET!!!
@CodeWithCypert
@CodeWithCypert Күн бұрын
BLAZINGLY FAST :)
@chrishabgood8900
@chrishabgood8900 Күн бұрын
@ years ago when I was learning elixir I saw microseconds also.
@CodeWithCypert
@CodeWithCypert Күн бұрын
@ don’t you lie to me, Chris ;) I jest, of course :) years back I worked at a company that was using Elixir pretty heavily (Ruby shop that was moving to Elixir) and while I had a couple of common gripes about the syntax, I was really impressed with how fast Elixir and the BEAM truly was. I considered committing to only writing elixir but pain points with the syntax really started wearing down on me (I don’t like Ruby either for what it’s worth). What were you building in Elixir?
@chrishabgood8900
@chrishabgood8900 Күн бұрын
@@CodeWithCypert nothing just started learning. I am ruby on rails dev.
@CodeWithCypert
@CodeWithCypert Күн бұрын
@ fair enough! Do you like RoR?
@EightSixx
@EightSixx Күн бұрын
can we get a Zig SQLite tutorial now? :D
@CodeWithCypert
@CodeWithCypert Күн бұрын
I see you, and I’ll see what I can do!
@EightSixx
@EightSixx Күн бұрын
Zinc looks way nicer :D
@CodeWithCypert
@CodeWithCypert Күн бұрын
I agree, but so many people have suggested http.zig by KarlSeguin and I am really digging that too. I am actually going to convert this project over to http.zig as a comparison
@pietraderdetective8953
@pietraderdetective8953 Күн бұрын
@@CodeWithCypert Jetzig is built on top oh http.zig and it's like the equivalent of Django and Rails in Zig. I actually posted a comment on this but it got deleted by YT.
@andrewpavlov9128
@andrewpavlov9128 Күн бұрын
This whole approach with endpoints and controllers feels wrong. Try out a "routes" example in zap's repo, looks way nicer.
@CodeWithCypert
@CodeWithCypert Күн бұрын
Originally I ended up taking the routes approach, but my understanding with endpoints are that they were effectively switching on the http request method so that I didn’t have to - which, if the framework is offering to do that, I feel like I’d want it to do. That being said, I really appreciate the feedback (and don’t disagree - I’ve mentioned that parts of the solution feel really weird). I may look at refactoring this to a routes based approach instead though.
@CodeWithCypert
@CodeWithCypert Күн бұрын
So many people suggested http.zig based on what I liked and didn’t like about Zap and Zinc and I’m going to just refactor this project to that as a comparison. I’m not sure how but http.zig by KarlSeguin slipped under my radar, but it’s almost exactly what I’m looking for (or at least, from the readmes). I’ll probably toss the controller approach with that refactor, too.
@seanknowles9985
@seanknowles9985 2 күн бұрын
Maaaaaaaa man, you made my day thanks so much for this, whats your handle on twitter? I will pm you and send a pack of beers.
@CodeWithCypert
@CodeWithCypert Күн бұрын
@bradcypert - feel free to PM me (I love talking with everyone) but if you wanna take the beer money and donate it to your local animal shelter, that’d make my day :)
@rocketsamiyou
@rocketsamiyou 2 күн бұрын
use ghostty :)
@CodeWithCypert
@CodeWithCypert 2 күн бұрын
I plan on trying it out soon!
Building a Redis clone with Zig and Codecrafters, part 1
23:44
Code With Cypert
Рет қаралды 1,2 М.
The standard library now has all you need for advanced routing in Go.
13:52
🎈🎈🎈😲 #tiktok #shorts
0:28
Byungari 병아리언니
Рет қаралды 4,5 МЛН
Thank you mommy 😊💝 #shorts
0:24
5-Minute Crafts HOUSE
Рет қаралды 33 МЛН
10 Signs Your Software Project Is Heading For FAILURE
17:59
Continuous Delivery
Рет қаралды 41 М.
Coding a Web Server in 25 Lines - Computerphile
17:49
Computerphile
Рет қаралды 362 М.
Jeff Dean: AI will Reshape Chip Design - NeurIPS 2024
43:53
GradientSpills
Рет қаралды 6 М.
Gamedev in Zig is actually pretty good...
16:28
Coding with Sphere
Рет қаралды 24 М.
Rust vs Zig Showdown (HTMX Webapp)
19:57
Code to the Moon
Рет қаралды 25 М.
Andrew Kelley   Practical Data Oriented Design (DoD)
46:40
ChimiChanga
Рет қаралды 169 М.
Get Good at Zig with these resources for learning the language
14:24
Code With Cypert
Рет қаралды 6 М.
I hated Zig's build system when I first started learning Zig
8:03
Code With Cypert
Рет қаралды 4,6 М.
HTTPS, SSL, TLS & Certificate Authority Explained
43:29
Laith Academy
Рет қаралды 159 М.
🎈🎈🎈😲 #tiktok #shorts
0:28
Byungari 병아리언니
Рет қаралды 4,5 МЛН