Hello Suave with Mono and macOS

Matthew Doig
3 min readDec 9, 2016

--

With the continued tooling malaise affecting .Net Core and wait for .Net Standard 2.0, Mono remains the only viable solution for running Suave on macOS and Linux.

Thankfully, because of the hard work of the F# community, setting up Suave on Mono is trivially easy.

The following howto was actually part of a far more interesting article on serving up Liquid templates, but was takign up too much space, so I’ve broken it off as a rather basic howto on getting Suave running on Mono.

Hello Suave

We’ve looked at Suave before and introduced some of the concepts that make it such an interesting piece of technology, web server as a function, declarative routing, combinators, etc.

In that article we set it up on .Net Core, and so this time we’ll run our web server as function on Mono.

  • Create a folder named HelloSuave
  • open VS Code in this folder
  • ⌘ + Shift + P to open the command palette
  • F#:New Project
  • Choose Suave Application
  • Name it HelloSuave
  • ⌘ + F5 to build

And voila…

syntax error: unexpected end of file

It’s always rather disconcerting when you first try running something and it doesn’t work out of the box. Your brain sort of scrambles about trying to make sense of the situation. And once it can’t make sense of the situation then it’s time to start googling.

Thankfully, it’s an issue that has been reported already.

Hello Fix

The fix appears to be relatively straight forward, as it simply requires running sed to remove the blue carriage return character in the default build.sh file.

However, in reality I found it takes a bit more fiddling than what it probably should, at least it did for me.

  • ctrl + ~ opens up the integrated bash shell
  • sed -e “s/^M//” build.sh > newbuild.sh
  • to enter the ^M type ctrl v + m
  • sed -e “s/^M//” build.sh > build.sh
  • this will blank out build.sh
  • copy the text from newbuild.sh to build.sh
  • remove newbuild.sh

Not sure why i have to run -sed on build.sh versus simply using the newbuild.sh output, but that was the magic sauce that gets the project building.

So let’s try that one more time,

  • ⌘ + F5 to build

And voila…phew it builds!

Hello Suave Take 2

Now that we’ve got a build going let’s open up our command line and run the output.

  • cd build
  • mono TodoMono.exe
[I] 2016–12–09T15:36:36.4471210Z: listener started in 90.151 ms
with binding 127.0.0.1:8083 [Suave.Tcp.tcpIpServer]

Our server is ready to go so let’s browse to the output and we should see the following.

Hello World!

On to More Exciting Endeavors

Like is said, this article is basic how to on setting up a Suave project on Mono. Next time we’ll do something a bit more exciting and server up actual html using the Liquid templating engine.

--

--

Matthew Doig

A programmer looking for ways to see the forest instead of the trees.