Suave is a lightweight, non-blocking web server. The non-blocking I/O model is efficient and suitable for building fast, scalable network applications. In fact, Suave is written in a completely non-blocking fashion throughout. Suave runs on Linux, OS X and Windows flawlessly.
Suave is inspired in the simplicity of Happstack and born out of the necessity of embedding web server capabilities in my own applications. Suave supports Websocket, HTTPS, multiple TCP/IP bindings, Basic Access Authentication, Keep-Alive, HTTP compression and many more capabilities.
To install Suave, add the following to your paket.dependencies:
Or you can use the legacy NuGet command line Package Manager Console:
The simplest possible application: Hello World!
The simplest Suave application is a simple HTTP server that greets all visitors
with the string
The above statement will start a web server on default port 8083 over HTTP.
startWebServer takes a configuration record and the WebPart
World") It’s worth noting that with the above, your application will block on
the function call, until you cancel the
Async.DefaultCancellationToken. If you
want to handle disposal of the async yourself, have a look at
To test the above yourself, paste that code in
Hello.fsx and then invoke it
fsharpi Hello.fsx (or
fsi Hello.fsx on Windows). Completely new? Here
are installation instructions on OS X/macOS,
Linux. If you have Visual Studio installed you
should be able to find the “F# Interactive” in your menus.
If you are running in an IDE, and not starting Suave via
want to provide a way of stopping the server without having to restart the IDE;
the code below will run the server until a key is pressed in the console window,
then shuts down the server.
In suave, we have opted to write a lot of documentation inside the code; so just hover the function in your IDE or use an assembly browser to bring out the XML docs. You can also browse our API reference.