Building an Asynchronous HTTP Server

Unfortunately, we can’t simply reuse our previous parsing methods. Most important, we can’t do blocking socket I/O as we did in Chapter 3, Writing a Simple HTTP Client, so we’ll need to adapt all the I/O patterns to libuv.

We’ll also want to think hard about memory allocation. With the low-overhead, asynchronous architecture we’ve used in this chapter, our server could potentially be handling thousands of requests per second. At that scale, the overhead of garbage collection, or even manual memory allocation, can have a serious impact on performance.

Designing the API

Before we get into the guts of the implementation, though, let’s take a moment to work through the design of an API that we could present ...

Get Modern Systems Programming with Scala Native now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.