frank: the web api dsl
DESCRIPTION
Most .NET web applications today use ASP.NET WebForms or MVC. However, several F# libraries offer new ways to build web APIs and applications help reduce code and offer better abstractions, especially for single-page applications (SPA). How can F# improve the situation? Frank is a minimal, domain-specific library designed to leverage the power of HTTP using functions directly.TRANSCRIPT
![Page 1: Frank: The Web API DSL](https://reader035.vdocuments.mx/reader035/viewer/2022081514/5596c8221a28ab6f5a8b4761/html5/thumbnails/1.jpg)
FrankThe Web API DSL
![Page 2: Frank: The Web API DSL](https://reader035.vdocuments.mx/reader035/viewer/2022081514/5596c8221a28ab6f5a8b4761/html5/thumbnails/2.jpg)
Ryan RileyO Logos Bible Software
O Community for F#
O F# MVP
O OSS: FSharpx, Fracture, Frank
O @panesofglass
![Page 3: Frank: The Web API DSL](https://reader035.vdocuments.mx/reader035/viewer/2022081514/5596c8221a28ab6f5a8b4761/html5/thumbnails/3.jpg)
HTTP PartsO Request/Response Lines
O Methods, URIs, Status Codes
O Headers
O General, Request, Response, Content
O Resources
O Representations
O Hypermedia
![Page 4: Frank: The Web API DSL](https://reader035.vdocuments.mx/reader035/viewer/2022081514/5596c8221a28ab6f5a8b4761/html5/thumbnails/4.jpg)
FrankO F# DSL using System.Net.Http
O Headers composition
O Follows the natural composition of HTTP
O Frank Resources == HTTP Resources
O Define your own conventions!
![Page 5: Frank: The Web API DSL](https://reader035.vdocuments.mx/reader035/viewer/2022081514/5596c8221a28ab6f5a8b4761/html5/thumbnails/5.jpg)
Function CompositionO Functional programming offers solutions
to these problems
O Filter
O Map
O Reduce
![Page 6: Frank: The Web API DSL](https://reader035.vdocuments.mx/reader035/viewer/2022081514/5596c8221a28ab6f5a8b4761/html5/thumbnails/6.jpg)
Simplest HTTP Application
HttpRequestMessage -> HttpResponseMessage
![Page 7: Frank: The Web API DSL](https://reader035.vdocuments.mx/reader035/viewer/2022081514/5596c8221a28ab6f5a8b4761/html5/thumbnails/7.jpg)
Simplest HTTP Frank Application
HttpRequestMessage -> HttpResponseMessage
HttpRequestMessage -> Async<HttpResponseMessage>
![Page 8: Frank: The Web API DSL](https://reader035.vdocuments.mx/reader035/viewer/2022081514/5596c8221a28ab6f5a8b4761/html5/thumbnails/8.jpg)
ResourcesGET /item/1
+ POST /item/1
+ PUT /item/1
+ OPTIONS /item/1
=
Resource at / with GET, POST, PUT, &
OPTIONS
![Page 9: Frank: The Web API DSL](https://reader035.vdocuments.mx/reader035/viewer/2022081514/5596c8221a28ab6f5a8b4761/html5/thumbnails/9.jpg)
Define a Method Handler
// handler
let echo request = async {
let! body = request.Content.AsyncReadAsString()
return HttpResponseMessage.ReplyTo(request, body)
}
// method handler
get echo
![Page 10: Frank: The Web API DSL](https://reader035.vdocuments.mx/reader035/viewer/2022081514/5596c8221a28ab6f5a8b4761/html5/thumbnails/10.jpg)
Define a Resource
let helloworld request = async { … }
let echo request = async { … }
let resource = route “/” (get helloworld <|> post echo)
![Page 11: Frank: The Web API DSL](https://reader035.vdocuments.mx/reader035/viewer/2022081514/5596c8221a28ab6f5a8b4761/html5/thumbnails/11.jpg)
HTTP Applications/
+ /items
+ /item/{itemId}
+ /help
=
Typical HTTP “application”
![Page 12: Frank: The Web API DSL](https://reader035.vdocuments.mx/reader035/viewer/2022081514/5596c8221a28ab6f5a8b4761/html5/thumbnails/12.jpg)
Define an Application
let todoListResource = route “/” (get todoList <|> …)
let todoItemResource = route “/item/{1}” (put …)
let app = merge [ todoListResource; todoItemResource ]
![Page 13: Frank: The Web API DSL](https://reader035.vdocuments.mx/reader035/viewer/2022081514/5596c8221a28ab6f5a8b4761/html5/thumbnails/13.jpg)
Content Negotiation
Client Accepts Server Supports
application/xml;q=0.9
application/json;q=0.8
text/plain;q=0.5
application/json
text/plain
text/html
application/json
![Page 14: Frank: The Web API DSL](https://reader035.vdocuments.mx/reader035/viewer/2022081514/5596c8221a28ab6f5a8b4761/html5/thumbnails/14.jpg)
Leverage Conneg
val negotiateMediaType = formatters ->
HttpRequestMessage ->
string ->
Async<HttpResponseMessage>
let echo = negotiateMediaType formatters
<| fun request ->
request.Content.AsyncReadAsString())
![Page 15: Frank: The Web API DSL](https://reader035.vdocuments.mx/reader035/viewer/2022081514/5596c8221a28ab6f5a8b4761/html5/thumbnails/15.jpg)
Summary
![Page 16: Frank: The Web API DSL](https://reader035.vdocuments.mx/reader035/viewer/2022081514/5596c8221a28ab6f5a8b4761/html5/thumbnails/16.jpg)
ResourcesO ASP.NET Web Forms in F#
O ASP.NET MVC in F#
O Figment DSL for MVC
O Frank DSL for Web API
O WebSharper
O Pit FW
![Page 17: Frank: The Web API DSL](https://reader035.vdocuments.mx/reader035/viewer/2022081514/5596c8221a28ab6f5a8b4761/html5/thumbnails/17.jpg)
Thank you!O Please rate this talk:
http://speakerrate.com/talks/9334-frank-the-web-api-dsl