Skip to content

hadydotai/zig-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Server

This is an attempt at building a web server in Zig without dependencies beyond the standard library. The only good part about it is the router, ported from some Go code I wrote a while back (Note to self: publish that code).

The server has some poor telemetry, broken in some areas (doesn't track errors too well) but useful to see load and memory usage. It also contains a copy of a JWT implementation by leroycep/zig-jwt in jwt.zig license is preserved.

Background

I actually built this to complete an integration with Hubspot SSO. I needed to model the SSO flow and figured this would be as good as any other problem to crack my teeth on in Zig. All my systems programming experience is in C, so you can imagine how fun it was and in some cases frustrating, to jump into Zig blind and stumbling like a fool.

The highlights for me is the comptime, which I used extensively to make a decent routing DSL.

I can promise you that much, my original Go implementation for the same routing DSL is nowhere near as ergonomic.

Anyway, the code is provided as is. At some point I'll extract bits into seperate libraries useful for my work in Zig in the future. Until then, enjoy what you have.

Dragons

I feel rather obligated to mention that there's quite a few dungeons in there, the thread pool, the littered sleeps everywhere. All for a reason, I didn't want to spend time implementing some stackless coroutines abstraction somewhere or reliable async code.

There's also some memory leaks after prolonged uptime.

The main goal behind this was to get a server up and running with some capability of serving multiple users simultaneously and not crapping its pants, just so I mock Hubspot SSO workflow.

Build and run

zig build run

Generate RSA keys

openssl genrsa -out private.pem 2048
openssl rsa -in private.pem -outform PEM -pubout -out src/public.pem

License

Copyright (C) 2025 hadydotai

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.gnu.org/licenses/.

About

An attempt at building a web server in Zig without dependencies beyond the standard library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published