Suave.RouteTypeProvider


Suave.RouteTypeProvider

Documentation

The Suave.RouteTypeProvider library can be installed from NuGet:
PM> Install-Package Suave.RouteTypeProvider
The Suave.RouteTypeProvider library can be installed from Paket:
group Romcyber
  source https://www.myget.org/F/romcyber/api/v3/index.json
  nuget Suave.RouteTypeProvider
      

What is Suave.RouteTypeProvider ?

Suave is a FSharp lightweight web server principally used to develop REST APIs

We can declare templated and strongly typed routes like :

1: 
2: 
// a and b params are integers
let additionRoute = GET >=> pathScan "/add/%d/%d" (fun (a,b) -> OK((a + b).ToString()))

Suave.RouteTypeProvider is a library providing strongly typed and named params

1: 
2: 
type SayBonjour = routeTemplate<template="/bonjour/{Name:string}/{FirstName:string}/{Age:int}">
SayBonjour.Returns (fun m -> OK <| sprintf "Bonjour %s %s, your age is %d" m.Name m.FirstName m.Age)

The type provider will create a type for each route and you will be be able to access parameter properties using your autocompletion

Contributing and copyright

The project is hosted on GitHub where you can report issues, fork the project and submit pull requests. If you're adding a new public API, please also consider adding samples that can be turned into a documentation. You might also want to read the library design notes to understand how it works.

The library is available under Public Domain license, which allows modification and redistribution for both commercial and non-commercial purposes. For more information see the License file in the GitHub repository.

namespace RouteTypeProvider
namespace System
namespace Suave
module Operators

from Suave
module Filters

from Suave
module Successful

from Suave
val additionRoute : (HttpContext -> Async<HttpContext option>)

Full name: Index.additionRoute
val GET : WebPart

Full name: Suave.Filters.GET
val pathScan : pf:PrintfFormat<'a,'b,'c,'d,'t> -> h:('t -> WebPart) -> WebPart

Full name: Suave.Filters.pathScan
val a : int
val b : int
val OK : body:string -> WebPart

Full name: Suave.Successful.OK
type SayBonjour = routeTemplate<...>

Full name: Index.SayBonjour
type routeTemplate

Full name: RouteTypeProvider.routeTemplate


Create a route from template like "/user/modify/{id:int}/{name:string}/{birth:datetime}"
routeTemplate<...>.Returns(handler: routeTemplate<...>.Model -> HttpContext -> Async<Option<HttpContext>>) : HttpContext -> Async<Option<HttpContext>>
val m : routeTemplate<...>.Model
val sprintf : format:Printf.StringFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.sprintf
property routeTemplate<...>.Model.Name: string
property routeTemplate<...>.Model.FirstName: string
property routeTemplate<...>.Model.Age: int64
F# Project
Fork me on GitHub