Skip to content

Instantly share code, notes, and snippets.

@samueleaton
Last active November 29, 2020 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samueleaton/b2ed07ede6a6bc6cf45f98e53a32f664 to your computer and use it in GitHub Desktop.
Save samueleaton/b2ed07ede6a6bc6cf45f98e53a32f664 to your computer and use it in GitHub Desktop.
simple hello world server in F#
namespace MyApp
open Sol.Context
module Middlewares =
let authenticateAdmin next ctx =
let isAdmin = hasQueryParam "is_admin" ctx
if isAdmin then
next ctx
else
ctx |> setStatusCode 403 |> writeText "Access Denied"
module Handlers =
let getHome ctx =
ctx |> write "welcome home..."
let getArtist ctx =
let artistId = getRouteParam "artist_id" ctx
ctx |> writeText $"got artist: {artistId}"
// App Entry
namespace MyApp
module Program =
open Sol.Server
[<EntryPoint>]
let main args =
genServer()
|> setPort 3007
|> setRoutes Routes.routes
|> run
0
namespace MyApp
module Routes =
open Middlewares
open Handlers
open Sol.Route
let routes = [
// run authentication and them getHome if successful
get "/" (authenticateAdmin <| getHome);
get "/admin/{artist_id}" getArtist
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment