
Build a web service with F# and .NET Core 2.0 - LyalinDotCom
https://blogs.msdn.microsoft.com/dotnet/2017/09/26/build-a-web-service-with-f-and-net-core-2-0/
======
Multicomp
Look I'm no ML engineer or even a data scientist, I'm much closer to
PS/VBS/AutoIT land, writing C# Console Applications for really complicated
stuff and/or exposing helper methods via a simple web service, but I am
increasingly liking F# for its pattern-matching and type providers that let me
'lock down' bugs much more than I can in imperative languages. I get that I'm
probably misusing F# for general-purpose stuff, but no matter what I like that
I can write my helper web-services in F# now and not just C#/VB.

Hopefully F# will become even more mainstream than it is right now.

~~~
zghst
I started out during the Node + JS revolution and I am more than certain I am
seeing a similar level of innovation happening in F#. The community is titled
towards more mathematicians and scientist, but mainstream adoption is right
around the corner.

~~~
nulagrithom
I've been on an ASP.NET Core project full-time for a year. Lately, I find
myself wondering "Would it be nicer to write this part in F#?" almost every
day.

There's some inertia there simply because I keep thinking that the next person
will hate me for forcing F# on them, but it's almost a siren call at this
point... I might have to just pull the trigger and commit a .fs file.

~~~
phillipcarter
Author here:

Go for it! Wiring up a new F# project is quite simple:

    
    
        dotnet new library -lang F# -o FSLib
        cd CSharpASPNETApp
        dotnet add reference ../FSLib/FSLib.fsproj
    

There are some templates in the .NET Core SDK for ASP.NET as well, so if folks
are wondering if it's possible to use F# with ASP.NET Core, the answer is yes!
There's even support for async controller actions using F# async expressions,
so there's no need to do some of the more awkward interop between Async and
Task.

------
sremani
Even though CLI improved with .net core 2.0, am I the only person feeling
Interactive F# is missing? I know on Mono its fsharpi, but does .net core even
has an equivalent ?

~~~
phillipcarter
Author here:

We haven't completed F# Interactive work for .NET Core yet. There are some big
technical problems to solve there, and it's our top priority after we complete
full support for the new project types in Visual Studio. Not timeline yet, but
a workaround is to use fsharpi (from Mono) on unix or fsi.exe on Windows. Both
use the same compiler that you get with .NET Core.

------
polskibus
What's the recommended way of doing SOA/microservices in .NET world these
days? Are people still using WCF mostly? Or is there a clear new winner?

I'm searching for a new stack that will be both easy to work with, yet full of
pluggable features if necessary (auth, async and non async channels, etc.).
Since WCF is not present in .NET Core (will it ever be?), it would be good to
find something solid that will last for as long as WCF did.

~~~
zombieburger123
Azure Service Fabric replaces WCF. It takes all the good parts (like the
interface-based programming model, interception pipeline etc.), throws out the
unneeded complexity (around bindings, configuration etc.) and comes with
built-in service discovery, fail-over, monitoring, deployment with rolling
updates, and much more. It also supports the actor model with automatic state
replication. Together with Azure Service Bus and CosmosDB it's the best stack
for developing real-world .NET SOA systems.

~~~
polskibus
That is not open source though, kind of skewed toward cloud deployments too. I
need a stack that works perfectly on-premises and does not need additional
services or artifacts to deploy. Does ASF meet such requirements?

~~~
zombieburger123
Unfortunately I don't think SF meets your requirements. Even though you can
run SF on-premises, this still requires you to install the SF cluster software
on the nodes (VMs) that make up the cluster.

~~~
polskibus
Another issue is that MS can decide at any moment to withdraw on-prem SF like
they did with Service Bus.

------
bsaul
i wish this was written 3 months ago. Knowing what tools and libs i should use
when coding in f sharp to perform a simple crud web api really was
frustratingly difficult (for something that should be at the homepage of any
server side language).

it made me quit and try a different language (swift), and now i think i'll
stay in that boat.

That's too bad, because i really liked the idea of coding in an ML family
language.

~~~
phillipcarter
Author here:

Never hurts to give it a try again! Three months ago, .NET Core 2.0 hadn't
actually shipped yet. Although it was certainly possible to write these sorts
of things on .NET Core 1.0, there was a significant lack of APIs which
prevented many people from using .NET Core. Now that 2.0 has been released, I
figured it was as good a time as any to push the use of F# for web services.

I'll also be posting next month about using Fable to write "full stack" F#
with .NET Core (Fable compiling to JS, F# with the Suave library on the
backend). It'll be a bit more involved (docker, deploying to Azure, etc.), so
I hope that it's useful to folks. Perhaps after that's posted, you'd be
interested in giving it another go?

~~~
Rapzid
In your opinion could Giraffe shape up to be a serious competitor to Phoenix
Framework for mind share? If the F# community could get something like that
off the ground I think it would do wonders for the platform.

Also, what's your opinion of Fable vs TypeScript as far as support for
interacting with existing libraries? Fable sounds very appealing, however all
the momentum behind TypeScript, its type features aimed at typing in-the-wild
js code, and the massive defintely typed project are hard to pass over..

~~~
ReedCopsey
One of the big strengths of Fable is that it can easily work with existing
TypeScript bindings. ts2fable allows you to convert a TypeScript binding to be
used with Fable, which allows you to leverage that mindshare easily.

~~~
Rapzid
I was/am worried about the type gymnastics the TypeScript team has done to
support in the wild code not being compatible with systems like scalajs and
Fable(F#). Giving it another look now though, it's pretty promising seeing
that Alfonso has implemented erased union types and even opened an issue to
have them added to F# :)

------
lenkite
F# _still_ doesn't have UWP support nor is supported by .NET native compiler.

~~~
bonesss
F# does not need UWP support since MS have allowed ["desktop bridge"
apps]([https://github.com/Microsoft/visualfsharp/issues/1096](https://github.com/Microsoft/visualfsharp/issues/1096))
(which may or may not signal the unofficial death of UWP...).

The .NET native compiler has some issues with handling valid tail recursion
MSIL commands IIRC - they're working on it.

F# will always come in second in the MS tooling wars.

Interesting, though, to follow the track record of MS techs that come in first
in their tooling wars over the last decade... Maybe being a bit slow on the
uptake of the "latest and greatest" EF, or Oslo models, or Silverlight, or
WPF, or WCF, or dotnetcores new project format, or UWPs new APIs isn't the
worst thing if you want your solutions to be supportable in production for a
while.

~~~
pjmlp
Microsoft is pretty explicit that it is a stop gap to port applications to
UWP.

That has been their main message in any presentation about the Desktop Bridge.
Always showing how an existing application gets packaged, followed by
replacing Win32 legacy features with modern UWP ones.

The track record of other tech giants is not much different, let alone the
usual reboots on GNU/Linux desktop stack.

------
hdhzy
Is there a recommended Docker base image that I can use to run F# web
services?

~~~
zghst
Any image with mono should be quite sufficient to run a F# Docker app.

Pick any of the following Dockerfiles:
[https://hub.docker.com/_/mono/](https://hub.docker.com/_/mono/)

~~~
hdhzy
Thanks! Are there any based on .NET Core? Not that I have anything against
Mono but I'd like to get setup similar to what is described in the article.

~~~
piaste
There are official dotnetcore images.

[https://hub.docker.com/r/microsoft/dotnet/](https://hub.docker.com/r/microsoft/dotnet/)

