2017-11-22

How to create an http2 app in F#

You can create an http2 web app in F# by targeting the Node.js JavaScript runtime with Fable, an F# to JavaScript compiler. Yesterday, I merged in a series of pull requests to ts2fable@next so that it can generate Node.js bindings for Fable from the TypeScript @types/node definitions. The entire Node.js API is available in F#, including its http2 module in F#. To get started, I've ported the server-side example from the Node.js HTTP2 documentation and put it in a dotnet template for you to try it out with. Here is a video demo:




Quick Start from Template

You need the latest dotnet sdk, yarn, and Node.js installed. I have dotnet 2.0.3, yarn 1.3.2, and node 9.2.0 installed. If you are on Mac or Linux, just run the commands directly from the scripts.

use-template.ps1 loading ...

HTTP/2 Getting Started in F#

I ported the getting started example to F# on top of the generated bindings. A nice feature o the aspect is that the F# functions are first class with curried arguments. Using an API with a lot of method overloads and unnamed TypeScript unions isn't the friendliest from F#, but it works. A more F# friendly API could definitely sit on top of these lower level bindings. Here is my port of the example:

App.fs loading ...

Option for Null Safe APIs

dotnet is Introducing Nullable Reference Types in C# and I applaud this effort. Hunting down NullReferenceExceptions is painful and time consuming. Cleaning nulls from the dotnet platform and many of its APIs is going to be a major effort. TypeScript did an amazing job with helping remove nulls problems by introducing Null and undefined aware types in TypeScript 2.0 along with a --strictNullChecks compiler option. ts2fable is able to benefit from null and undefined aware types being modeled in the TypeScript definition files. ts2fable generates F# option types for the null and undefined aware TypeScript types. This makes the ts2fable generated APIs safer than many of the existing dotnet APIs.

Available for Hire

I have done the work on ts2fable in part to show off my software engineering skills. I am seeking a full time remote job. This last month, I was very close to getting a job in San Francisco and another in New York. Unfortunately, I am still looking. If you know of an F#, Fable, TypeScript, or Rust position, please reach out to me at https://www.linkedin.com/in/ctaggart/.