
Web application from scratch, part I - Bogdanp
https://defn.io/2018/02/25/web-app-from-scratch-01/
======
ggambetta
I love seeing projects/tutorials like this. Too many developers treat too many
layers of the stack as "magic", and this is great to show it's not so.

We should change the definition of "full-stack developer" to _" given a
computer, an opcode reference sheet, a way to enter bytes into a computer, and
enough time, is capable of making an operating system and a bunch of
applications"_ :)

~~~
blunte
I assume this is sarcasm.

Those who do not build upon the achievements of others are far less likely to
reach any new heights.

It's good to remember what we take for granted, and it's good to understand
what is happening in layers below our concern. But pragmatically speaking,
it's more valuable to know how to study and understand what's beneath us _when
we need_ rather than spending time proving ourselves just for the sake of
proving.

Do you still hunt, kill, and butcher your own meat?

~~~
ivanhoe
There's a huge difference between using the prepackaged black box solution for
the sake of efficiency (as everyone should), and not caring at all to
understand even the basics of how it actually works. The later usually leaves
one too intimidated to change anything and vulnerable to any unexpected
situation. And things break all the time, you need to debug problems with
tools and servers and run into all kinds of exotic issues. I once worked with
a front-end dev who would restart his machine when he needed to reset a local
web server, because "it's not his job" to learn a bit about using the command
prompt. For me that is plain crazy attitude and it's not that rare...

------
r0m4n0
Couldn’t help but think of this quote...

“If you wish to make an apple pie from scratch, you must first invent the
universe.” -Carl Sagan

~~~
matte_black
Now there's an article I'd like to see.

------
platz
> we need to create a socket, bind it to an address and then start listening
> for connections.

This is the most important part. Is there a tutorial on sockets, perferably
not written from a C perspective and in a language agnostic way? How OS
specific is it? Is there a common basis over most OSes?

~~~
acomjean
Since the socket/networking code is in the OS libraries its in C. Other
languages usually just wrap them. They're pretty similar across OSs (I used to
do sockets in linux/hpux and solaris).

There was a book I borrowed that was useful, UNIX Network Programming, Volume
1, Networking APIs: Sockets and XTI

I found beej's guide useful as well.
[http://beej.us/guide/bgnet/html/multi/syscalls.html](http://beej.us/guide/bgnet/html/multi/syscalls.html)

------
windlessstorm
Tried similar stuff few months back. Start a simple socket listening at port
80. Use any browser to make connection. After recieving any connection on
server, send a properly formated HTTP response ( precede with 200 ok and must
include content-length, everything else I found was optional). Now scale this
to include custom root locations. Extending this to handle all the
specifications the thousands of common protocols a server should handle will
now feel like headache, so here I didn't continued anymore.

Next I wanted to replace the browser with my own client. Soon realized how
huge of a obstacle I was heading towards. Got bogged down by the complexity of
a simple browser and still havn't got started on this. Maybe someday :D

------
pvsukale3
Cache link:
[http://webcache.googleusercontent.com/search?q=cache:defn.io...](http://webcache.googleusercontent.com/search?q=cache:defn.io/2018/02/25/web-
app-from-scratch-01/)

------
jventura
A blog post similar to this one (same content) that I did last year. I use it
as basis for a small project on how to implement an http server from scratch
in my distributed computing classes: [http://joaoventura.net/blog/2017/python-
webserver/](http://joaoventura.net/blog/2017/python-webserver/)

------
kazinator
Here is a not quite from scratch (uses Apache for CGI dispatch) application:

[http://www.kylheku.com/cgit/tamarind/tree/](http://www.kylheku.com/cgit/tamarind/tree/)

Tamarind allows users to manage throw-away e-mail aliases.

I've been using this almost daily for a few years.

It's self-contained; no framework or external libraries are required other
than what is in that directory. It just requires an installation of the TXR
language in which it is written.

Though it doesn't include its own HTTPD server, it's in a language that I made
myself. The arbitrary boundary defining "from scratch" could easily be moved
to encompass "own TCP/IP stack and ethernet driver" or "own filesystem", and
so on down to the hardware.

------
gkya
I think it's useful to know what your abstractions (i.e. the web framework and
the web server here) abstract away, so this is really nice material. But for
anything you're actually going to publish, using a well-founded framework or
library is the way to go, because so many things you can get wrong is fixed by
many smart people in such projects (i.e. Django, Rails, Nginx, Apache, &c).

~~~
plopz
Not to mention the difficulty that would be trying to roll your own https.

------
hiisukun
Here is the archive.org mirror, since the server is responding with error 503
(over capacity at the moment).

[https://web.archive.org/web/20180226040031/https://defn.io/2...](https://web.archive.org/web/20180226040031/https://defn.io/2018/02/25/web-
app-from-scratch-01/)

~~~
Bogdanp
Thanks! I woke up to realize the site was still on the free AppEngine tier and
had used up all the bw. It should be back up now. :D

------
bratah
I get over quota error.

------
mar77i
I think you should use .replace(os.linesep, "\r\n"), in case the system's
newlines coincide with CRLF.

~~~
gkya
If I'm not mistaken CRLF is part of the HTTP spec as a field separator.

Edit: I've read the article after this comment, now I see what the parent
comment meant. I guess in this case sth like "\r\n".join(["line1", "line2",
"line3"]) is best.

------
amanzi
This is interesting, but for an internet facing server I would rather use an
existing server that would be far more secure than anything I could create in
an afternoon.

~~~
Touche
Of course, but understanding what is going on is also of huge benefit to you.

~~~
amanzi
Yes, agree with that - I've created a mini web server in C# before, but I
wouldn't want to expose that to the internet.

