handmade.network » Forums » Web development in C
juankprada
Juan Prada
5 posts
#15897 Web development in C
1 month, 2 weeks ago Edited by Juan Prada on July 31, 2018, 4:03 p.m.

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
[email protected]
Ben Visness
23 posts

HMN technical staff, Handmade Math contributor, web developer, etc.

#15898 Web development in C
1 month, 2 weeks ago

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.
insofaras
Alex Baines
40 posts / 1 project
#15899 Web development in C
1 month, 2 weeks ago

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.
yumisen-yamasen
7 posts
#16247 Web development in C
1 week, 6 days ago

necro-ing and its a bit of a joke but https://learnbchs.org/