8
Github GitHub - nglabo/FSharp.Json.GiraffeSerializer: Giraffe JsonSerializer imp...
source link: https://github.com/nglabo/fsharp.json.giraffeserializer
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Usage
open FSharp.Json.GiraffeSerializer (* Open the module *) open Giraffe open Giraffe.Serialization.Json (* Open the module *) open Microsoft.AspNetCore.Builder open Microsoft.AspNetCore.Hosting open Microsoft.Extensions.DependencyInjection open Microsoft.Extensions.Hosting type U = Killua of string type T = { Killua: U option } let router = choose [ route "/" >=> (fun next context -> json { Killua = Some <| U.Killua "Zoldyck" } next context) ] type Startup() = member __.ConfigureServices(services: IServiceCollection) = services.AddSingleton<IJsonSerializer>(FSharpJsonSerializer()) |> ignore (* Register the IJsonSerializer class and all done! *) services.AddGiraffe() |> ignore member __.Configure(builder: IApplicationBuilder) = builder.UseGiraffe router [<EntryPoint>] let main args = Host .CreateDefaultBuilder() .ConfigureWebHostDefaults(fun builder -> builder.UseStartup<Startup>() |> ignore) .Build() .Run() 0
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK