liveBook · Manning

SAFE Stack

As explained in F# in Action: A Revised Edition of Get Programming with F#

SAFE Stack is an F#-oriented web development stack combining libraries and tools from the .NET and JavaScript ecosystems.

SAFE Stack is an F#-first web development stack for building both server and browser applications while keeping F# across the full application. It combines .NET and JavaScript ecosystem tools, enabling standards-compliant, rich web applications without giving up immutable data or expression-oriented code. section 13.5 section 13.5.1

Figure 13.12 The SAFE Stack is a collection of different technologies bundled together to allow writing standards-compliant, rich web applications entirely in F#. The left-hand side of this figure represents the server side of the stack; the right-hand side represents the client side, which typically runs in the browser as a so-called single-page application.

The stack separates server-side technologies from client-side technologies, with the browser commonly running a single-page application. section 13.5.1

The main pieces give common application tasks an F#-oriented shape:

  • Saturn extends Giraffe with quicker abstractions for common server tasks. section 13.5.1
  • Fable Remoting provides type-safe, RPC-style communication between browser and server over HTTP. section 13.5.1
  • Elmish supports the Model-View-Update pattern for structuring F# user interfaces. section 13.5.1
  • React supplies the user-interface library underneath the F# client experience. section 13.5.1

Create and run a starter application

Install Node.js v16 and npm v8, then install the SAFE template. Create a directory, enter it, run `dotnet new SAFE`, restore the tools with `dotnet tool restore`, and start the application with `dotnet run`. The generated application provides a to-do interface at `http://localhost:8080`, including adding items and real-time validation. Its in-memory list survives browser refreshes but resets when the application restarts. Use `--minimal` when a lighter template is preferable. section 13.5.2

How F# in Action: A Revised Edition of Get Programming with F# covers it

How deep it goes
Explains the stack’s purpose and principal components, then demonstrates setup and a generated application without detailing every technology.
Examples
Uses a generated to-do application with browser validation, persistence across refreshes, and an in-memory reset on restart.
What it assumes
Assumes Node.js v16, npm v8, and the dotnet toolchain, while providing a template that removes setup boilerplate.
What you can do after
Builds and runs a starter SAFE application using the dotnet template and its client-server development workflow.
How it connects
Connects Fable, .NET, JavaScript, Saturn, Giraffe, Fable Remoting, Elmish, MVU, React, and HTTP.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of F# in Action: A Revised Edition of Get Programming with F#. The section links point to the parts of the book it draws on.