We're running Building Solid Systems in F# in London, 31 Jan - 1 Feb 2018. High quality training for building .NET Core, F#, distributed production ready systems.
Single File Websites With Suave
As of a few days ago, the embedded module was merged into Suave master. Enjoy!
I'm a great fan of Suave for simple web development in F#. I highly recommend checking out the site for details, but in the mean time I'd like to share a little trick I've been using for rapid prototyping that I'm finding very useful.
The Suave.Http module contains a few helpers for serving static files from disk. Unfortunately, depending on use case and deployment strategy, relying on the location of a bunch of files on disk can be problematic.
Setting up your website looks something like this:
moduleWebsiteopenSystemopenSuave.HttpopenSuave.TypesopenEmbeddedletapp=choose[// serve the embedded index.html for "/"GET>>=url"/">>=resource"index.html"// check if the request matches the name of an embedded resource// if it does, serve it up with a reasonable cacheGET>>=browse_embedded// If it doesn't, try and trigger your api end pointsGET>>=url"/json">>==(fun_->serveJson<|makeData())GET>>=url"/carrier">>==(fun_->getCarrierCodes())// Nothing else has worked - 404NOT_FOUND"Sorry, couldn't find your page"]web_serverdefault_configapp
@ad3mar if you feel like rolling this into Suave, you can consider it licenced under what ever is most convenient. An official licence file would make me much happier using Suave in production, by the way (hint, hint).
Edit: ad3mar has pointed out in the comments that Suave is already Apache2 licensed, I just failed to find the file last time I looked.