Zig web server lib needed

I am building a free chat app based on websocket in zig.

My old plan is to use c lib but it seems that using uwebsockets or bun mdule is difficult(see my topic How to use bun in zig)

So are there any great zig web server on github?

I need a fast web server with tls and websocket support in the core, better written in pure zig.

What I had already seen:
zap(not written in zig, no complete tls support)
http.zig(no tls support)
zzz(no websocket support)

Could anyone help me to recommend some projects?

Thanks.

Please, slowdown a little with how you approach this.

You seem to approach this with wanting a ready made solution, that gives you everything you wanted, in a single ready made package, where you only need to add it as a dependency and copy the example.

I am not aware of a project that currently gives you this in Zig.
(If it exists, maybe it takes a while until the person that knows of that solution finds this topic and tells us about it)

I think instead you should approach it from the way of finding out whether you can use some project as the base and some other library to get what is missing.

It also is likely that you will have to figure out some things yourself,
because you have pretty specific requirements and unless somebody else already had the same requirements, it is unlikely that the perfect solution will just be given to you.

6 Likes

We aren’t a paid technical support forum, where you order what you want and somebody works to create it for you, so please change your attitude a bit, it comes across demanding, with the many topics you have created.

If you want free help, you need to demonstrate that you are participating (and also trying to help yourself) and reading and understanding the answers you have received, so exercise some patience, instead of creating new similar topics.

Further, it would be even better if you get started in a practical way, by picking a webserver library that could form the basis of your project and then trying to add the websocket part to that.

You can even document your progress, by letting us know which approach you picked, what you have found out along the way, what doesn’t quite work yet etc.
That way it becomes easy for other people, who are also interested in that, to let you know how you can add features, fix bugs or make something simpler.

If you can demonstrate that you have invested some time in your project and tried to come up with a solution yourself, it helps with people wanting to help and invest their time.

The people here, are following their individual interests and collaborate on what they are inclined to work on, out of their own interest.

Please respect the time and contributions of the individuals, whose help you are seeking here, if you don’t do that, then it isn’t a fair and equal exchange of value and ideas and not a positive interaction between people. We don’t want people to feel used, or exploited as a work force on this forum.

8 Likes

I don’t think it’s wrong attitude
Rather a language problem

I dont want to comment on the attitude, since that is subjective.

To clarify, he wants to get all of this without any work. Just to import it and be done (at least it came out that way in the limited communication we had).
Imho this is not a language fault. This is ecosystem fault AND to be honest i think the stuff hes requiring is missing in most ecosystems.

I gave him somewhat specific tutorial how to do it with the Tardy runtime (stuff ZZZ is running on and you can use stand-alone or even directly from ZZZ), which is not even hard to use, its conceptually verry similar to the way you would od so for example in C# or Go. Yes it has a bit more complexity because of no GC, but we are HERE because it is supposed to run fast no?

3 Likes

I couldn’t find a pure zig library or package that suits your need for now.

I think Zig is still a young programming language with a fairly small community and ecosystem.

In my opinion, if you really really want a website with websocket running in the next few weeks or months, you probably should go with another programming language with a more mature ecosystem for web development, such as go, rust, or python.

However, if you want to learn Zig and do everything in Zig, it is possible, since Zig is a system programming language. Anything a computer can do, it can be written in Zig, just like C or even Assembly. You will need to spend more time to develop and implement your own websocket, then combine with an existing web library, just like what sze and Bobvan mentioned.

2 Likes

Thank for all one’s help

I think my attitude is wrong, because I want to get all without work. There are libs in rust and go that can achieve my goal, but in zig there are not.

My original intention is to ask whether there is anyone know a networking framework and can reccomend it. I just love zig and want to work with it.

Maybe Bobvan is right, I need more work than in other programming languages, I will try tardy-org now.

Thanks

1 Like

I think your attitude is fine. You said what you want. And what you want is not a big ask for every mainstream language. This should be a simple answer for zig libraries too.

http.zig has a section in the docs about integrating with a web socket lib also by same author.

I’m not aware of any library which implements all of your requirements. TLS by itself is a rather massive undertaking.

As with any project, you have to start somewhere, and you likely won’t know the thorns until you start.

Here’s one way of starting:

  1. Assume there is a c library that does the hardest parts (like TLS). I think it’s reasonably likely that there is a TLS implementation in C that can help you later. And Zigs interop with C is easier than most other languages.
  2. Websockets are kind of like sockets. Maybe start with a demo that uses unix domain sockets between two clients. Or two clients and a server.
  3. After you’ve got some basics, you could layer on the extensive list of protocols you mentioned, one at a time. TLS, HTTP, Websockets, likely using some C dependencies.

Another way of starting:

  1. Use a python framework like FastAPI to get a really quick demo going. This can help teach you the basics of websockets and could be more motivating and fun at first.
  2. Then dive into the zig implementation.
2 Likes

Just use http.zig, and stick it behind caddy or nginx or traefik or whatever to handle tls

2c opinion - build simple services that do 1 thing well, and string them together. I wouldn’t want to manage a large system with lots of services, where each service managed its own tls termination / auth etc in its own special way

2 Likes

One of the reasons i reccomended the Tardy with secsoc in the first place, it has great runtime, complete implementation of TLS and exposes it all under VTable that is similar to Socket interface.

2 Likes

Just to give context, with attitude the above note mostly referred to the OP creating multiple separate topics that were all about mostly the same thing.
We merged most of those topics.

Wanting something to work is of course fine, in some areas the ecosystem just isn’t there yet.

Can’t believe I forgot about nginx / traefik. Definitely the way to go.

2 Likes

Thanks for the moderation. A thankless job no doubt.

1 Like

Drifting OT … but I recently discovered that traefik will manage auth as well by magic.

Put your service behind traefik, and you can config traefik to ensure that requests have a valid login token, orelse do the oauth loop and return the request with X-client-id already filled in

Nice to know, and reduces the amount of code on the zig side. I’m currently doing oauth manually in zig, but I’m not 100% comfy about having added that burden of getting auth right inside my app code :slight_smile:

1 Like

Ok thank for all of you

how about watching GitHub - sourlizi/zuws: Opinionated Zig bindings for uWebSockets
and see my post on How to use bun in zig - Help - Ziggit

Hey! just a heads up, I am currently working on a web framework with all the bells and whistles, excluding tls, as ngnix is the standard typical production approach. Its rough around the edges, but will make a post about it once its finished. It’ll include, oauth, websockets, and dynamic routing, ect, once it finished (a bit akin to golang fiber). Hopefully that’ll be enough :slight_smile:

1 Like

thanks
could you tell me your project’s name?

Its currently not open source, as I’m not really comfortable yet with the standard of code I’ve written, also it currently only running for macos. I have yet to implement it for windows and linux. Idk what your running atm? Or how much functionality you need? If you feel comfortable enough or want a challenge, you could look into forking zzz, and them implementing a version of
Websockets from this github

into zzz, this’ll also teach you a lot.

If your aim is to build an app, choose a robust framework like golang fiber, if you want to learn zig, maybe try http.zig or zzz, and build your own mini websocket lib. Sorry, I don’t have much else. I am pushing to release and initial version in the coming months.

2 Likes