Build full-stack web apps. Stay in F#.

Build reactive UIs, call server functions directly, and share types across your application - all with the power of F# and .NET.

Get started
$ dotnet new install WebSharper.Templates
[<JavaScript>]
module Client =
    type IndexTemplate = Template<"wwwroot/index", ClientLoad.FromDocument>

    let People =
        ListModel.FromSeq [
            "John"
            "Paul"
        ]

    [<SPAEntryPoint>]
    let Main () =
        let newName = Var.Create ""
        IndexTemplate()
            .ListContainer(
                People.View.DocSeqCached(fun (name: string) -> 
                    IndexTemplate.ListItem().Name(name).Doc()
                )
            )
            .Name(newName)
            .Add(fun _ ->
                People.Add(newName.Value)
                newName.Value <- ""
            )
            .Bind()
Terminal
VITE v6.3.5 ready in 663 ms
➜ Network: use --host to expose
➜ press h + enter to show help
█

Trusted by fast-growing companies around the world

How it works

Write your app once in F#, C# or OCaml. One dotnet build turns it into a native server, a JavaScript client and the typed contract between them.

shared server browser

WebSharper compiler

$ dotnet build

  • ✓Server: assembly, remote endpoints
  • ✓Client: ES modules, typed proxies
  • ✓JSON for the shared types
  • ✓Routes, .d.ts, source maps

Server ASP.NET Core · OCaml

Pages, typed routes and the Search endpoint, in a host you already know how to run.

typed call · JSON both ways

Browser JavaScript

Readable ES modules that call the server like a local function, with TypeScript declarations and source maps.

One file, both tiers

Mark what runs where. The compiler runs the server part as .NET, the client part as JavaScript, and writes everything in between.

Runs on the server

Search

Native .NET, behind a remote endpoint the compiler adds to your server.

Product on both sides

One record: the same fields, equality and JSON format in .NET and in JavaScript.

Shop.fs one file · one language
type Product = { Name: string; Price: float }[<Rpc>]
let Search (q: string) = async {
    return Db.products |> Array.filter (fun p -> p.Name.Contains q) }[<JavaScript>]
let SearchBox () =
    let results = Var.Create [||]
    Templates.Main.SearchForm()
        .OnSearch(fun e -> async {
            let! found = Search e.Vars.Query.Value
            results.Value <- found } |> Async.Start)
        .Results(results.View |> Doc.BindSeqCached ProductItem)
        .Doc()

Runs in the browser

SearchBox

An ES module that renders the form and updates the list as results arrive.

Search as a call

A typed client proxy: the arguments and the result are serialized for you.

Glue you don't write: fetch() DTOs API routes JSON mapping a generated API client

Functional, reactive applications with WebSharper.UI

Bind composite data models to your reactive user interfaces. The flow of reactive values through the code yet concise, readability.

let x = Var.Create 1
let y = Var.Create 1

// Fill the holes in index.html and bind it to the page.
IndexTemplate()
    .X(x)
    .Y(y)
    .Sum(View.Map2 (fun x y -> string (x + y)) x.View y.View)
    .Bind()
Search

Powerful UI abstractions

Declare full interactive forms in just a few lines of code with WebSharper Forms.

let LoginForm () =
    Form.Return (fun user pass -> user, pass)
    <*> (Form.Yield ""
        |> Validation.IsNotEmpty "Must enter a username")
    <*> (Form.Yield ""
        |> Validation.IsNotEmpty "Must enter a password")
    |> Form.WithSubmit
    |> Form.Run (fun (u, p) ->
        JS.Alert("Welcome, " + u + "!")
    )
    |> Form.Render (fun user pass submit ->
        form [] [
            div [] [label [] [text "Username: "]; Doc.InputType.Text [] user]
            div [] [label [] [text "Password: "]; Doc.InputType.Password [] pass]
            Doc.Button "Log in" [] submit.Trigger
            div [] [
                Doc.ShowErrors submit.View (fun errors ->
                    errors
                    |> Seq.map (fun m -> p [] [text m.Text])
                    |> Doc.Concat)
            ]
        ]
    )
    
IndexTemplate()
    .LoginForm(LoginForm())
    .Bind()
Search

Web Workers without hassle

Write client-side parallel code directly in your code.

The compiler automatically creates the separate trimmed JavaScript file for the web worker.

Worker.fs
let worker = new Worker(fun self ->
  // This code runs in the worker:
  self.OnMessage <- fun e ->
      Console.Log(
        "Received message from main thread: " 
        + string e.Data
      )
)

// This code runs in the main thread:
worker.PostMessage("Hello, worker!")
index.js
var worker = new Worker("worker.js");
worker.postMessage("Hello, worker!");
worker.js
self.onmessage = function (e) {
    console.log(
       "Received message from main thread: "
           + e.data.toString());
}
Terminal

Fewer seams, not just fewer lines

In a typical full-stack app much of the code at the boundary is glue. WebSharper generates it, so one compiler checks both sides at once, and so does your coding agent's next build.

A typical full-stack app

Two languages, two toolchains, glue at every boundary.

React UI TypeScript
fetch calls and their types, by hand
API client generated from OpenAPI
DTOs and JSON mapping
Controllers and routes C#
validation kept in step by hand
Domain and data C#

With WebSharper

One project. The compiler writes the boundary.

UI, remote calls and domain in one language

Client code, remote functions and shared types, in F#, C# or OCaml.

✓ generated: endpoints, proxies, JSON, routes
Browser: ES modules + .d.ts, source maps
✓ typed both ways, checked by every build
Server: ASP.NET Core your auth, DI, EF Core

1

language and type system

0

hand-written boundary layers

The whole stack, at a glance

What you write, what WebSharper does with it, and what you ship.

You write

F#

Unions, records, computation expressions

C#

Records, LINQ, async/await

OCaml experimental

Modules, variants

DSL spec

Generated into F#

WebSharper

One compiler, one typed model of your app

Type-check Translate Generate the glue Bundle

You ship

Server

Native ASP.NET Core or OCaml: pages, routes, auth and your data access.

Typed contract, generated

Remote endpoints Client proxies JSON Routes

Browser

Readable ES modules, .d.ts for TypeScript, source maps back to your code.

Get Started

Instant access to the power of WebSharper

Get started
$ dotnet new install WebSharper.Templates