Skip to content

Application

run

Runs Saturn application.

Input: IWebHostBuilder

Application builder

Computation expression used to configure Saturn application. Under the hood it's using ASP.NET application configurations interfaces such as IWebHostBuilder, IServiceCollection, IApplicationBuilder and others. It aims to hide cumbersome ASP.NET application configuration and enable high level, declarative application configuration using feature toggles.

Example:

let app = application {
    pipe_through endpointPipe

    use_router topRouter
    url "http://0.0.0.0:8085/"
    memory_cache
    use_static "static"
    use_gzip
}

use_router

Defines top-level router used for the application. It calls IApplicationBuilder.UseGiraffe.

Input: HttpHandler

application {
    ...
    use_router myRouter
}

pipe_through

Adds pipeline to the list of pipelines that will be used for every request.

Input: HttpHandler

application {
    ...
    pipe_through requestId
}

error_handler

Adds global error handler for exceptions not handled anywhere else. It uses IApplicationBuilder.UseGiraffeErrorHandler.

Input: Exception -> ILogger -> HttpHandler

application {
    ...
    error_handler (fun e log -> text e.Message)
}

url

Defines the URL on which the application will be hosted. Should include port.

Input: string

application {
    ...
    url "http://0.0.0.0:8085/"
}

memory_cache

Enables in-memory session cache. Required if you used fetchSession plug.

application {
    ...
    memory_cache
}

use_gzip

Enables automatic gzip compression.

application {
    ...
    use_gzip
}

use_static

Enables static file hosting. Input path defines WebRoot and ContentRoot of application.

Input: string

application {
    ...
    use_static "static"
}

use_config

Defines configuration that can be used with the HttpContext.GetConfiguration() function. The configuration function is evaluated once, during first request of the application.

Input: unit -> 'a

application {
    ...
    use_config (fun _ -> "config")
}

force_ssl

Redirect all HTTP request to HTTPS.

application {
    ...
    force_ssl
}

use_cors

Enables application level CORS protection. First parameter is the name of the policy. Second parameter is configuration builder setting policy options.

Input: string -> (CorsPolicyBuilder -> unit)

application {
    ...
    use_cors "CORS_policy" (fun builder -> ())
}

use_iis

Enables IIS integration.

application {
    ...
    use_iis
}

use_jwt_authentication

Enables default JWT authentication. The first parameter is a private key used in signing. The second one defines the issuer of the token.

Input: string -> string

application {
    ...
    use_jwt_authentication "mySecretKey" "lambdafactory.io"
}

use_jwt_authentication_with_config

Enables JWT authentication with custom configuration.

Input: JwtBearerOptions -> unit

application {
    ...
    use_jwt_authentication_with_config (fun opts -> ())
}

use_cookies_authentication

Enables default cookies authentication.

Input: string

application {
    ...
    use_cookies_authentication "lambdafactory.io"
}

use_cookies_authentication_with_config

Enables cookies authentication with custom configuration.

Input: CookieAuthenticationOptions -> unit

application {
    ...
    use_cookies_authentication_with_config (fun opts -> ())
}

use_github_oauth

Enables default GitHub OAuth authentication.

Input: string -> string -> string

application {
    ...
    use_github_oauth "myClientId" "myClientSecret" "/login"
}

use_github_oauth_with_config

Enables GitHub OAuth authentication with custom configuration.

Input: OAuthOptions -> unit

application {
    ...
    use_github_oauth (fun opts -> ())
}

use_custom_oauth

Enables custom OAuth authentication.

Input: string -> (OAuthOptions -> unit)

application {
    ...
    use_custom_oauth "LinkedIn" (fun opts -> ())
}

The functions below enable you to add any configuration using standard ASP.NET builders

app_config

Adds custom application configuration step.

Input: IApplicationBuilder -> IApplicationBuilder

host_config

Adds custom host configuration step.

Input: IWebHostBuilder -> IWebHostBuilder

service_config

Adds custom service configuration step.

Input: IServiceCollection -> IServiceCollection

let serviceConfig (services: IServiceCollection) =
    services.AddSingleton<IMySingleton, MySingleton>()
    services.AddTransient<SomeTransientService>()

let app = application {
    ...
    service_config serviceConfig
}

logging

Adds logging configuration.

Input: IloggingBuilder -> unit