The 2024 Wheel Reinvention Jam just concluded. See the results.

Web development in C

Hi Guys,

I am thinking on making a web application. I've always done that using Java and its bloated environment, so I was thinking on making this new web app in C. I really don't know if it is a good idea or not, but I've had a bit of trouble finding out where to start, as most of the documentation for Web development is not really for C.

Most of the docs I find, point me to use FastCGI, but it seems that project is dead. CGI still is an alternative but, performance is an issue, and knowing how CGI works, I know things won't end up well using it.

So I decided to post a question here, to check if any of you know which path should I follow. Maybe is it using GNU's libmicrohttpd? making my own http server from scratch? I know the idea here is to aim to not use libraries, but the idea behind my project is not to make an http server, but an application... So, I really don't know what to do.

Recomendations and approaches are welcome.

Thanks

Edited by Juan Prada on
It's not that handmade projects shouldn't ever use libraries - it's more that you should be conscious of everything your program is doing, cut away unnecessary abstraction, and focus on performance and elegance. Also, it's really tough to do web stuff "properly" without the use of libraries, especially if you want to handle newer technologies like HTTP/2.

I'm not familiar with server options in C, but if you're looking for a C-like option that isn't as bloated as a Java app, I would recommend looking into Go. Go itself is a compiled language with a lot of similarities to C (although it is garbage-collected), and the http package in Go's standard library makes it easy to get a basic HTTP server up and running, without prescribing much else.

If you are used to bigger web frameworks and want features like middleware functions, you could also use a simple framework like Gin, which gives you a more conventional framework structure but is still nowhere near as bloated as your average Java framework.
If you want a C web framework you could take a look at Kore. I've been interested it in for a while myself but haven't built anything yet.

Plain old CGI is also surprisingly fast with C, I use it for https://dev.abaines.me.uk/quotes/

Obviously you have to be a bit more careful than if you were using a scripting or higher-level language (security-wise) - but paying close attention to what you write is what "handmade" is all about. I believe Kore uses seccomp and a chroot to help, too.
necro-ing and its a bit of a joke but https://learnbchs.org/