ch 6

SAFE Template Overview

Client/Server messaging

1. Fable.Remoting

2. Raw HTTP

Fable.Remoting

Shared

module Route =
    let builder typeName methodName =
        sprintf "/api/%s/%s" typeName methodName

type ITodosApi =
    { getTodos: unit -> Async<Todo list>
      addTodo: Todo -> Async<Todo> }

Sever

let todosApi =
    { getTodos = fun () -> async { return storage.GetTodos() }
      addTodo =
          fun todo ->
              async {
                  match storage.AddTodo todo with
                  | Ok () -> return todo
                  | Error e -> return failwith e
              } }

let webApp =
    Remoting.createApi ()
    |> Remoting.withRouteBuilder Route.builder
    |> Remoting.fromValue todosApi
    |> Remoting.buildHttpHandler

//http:localhost:8085/api/ITodosApi/getTodos
//http:localhost:8085/api/ITodosApi/addTodo

Client

let todosApi =
    Remoting.createApi ()
    |> Remoting.withRouteBuilder Route.builder
    |> Remoting.buildProxy<ITodosApi>

MongoDB F#

Serilog

References

https://safe-stack.github.io/docs/recipes/client-server/messaging/ https://safe-stack.github.io/docs/recipes/client-server/messaging-post/

return to Outline