Date post: | 10-May-2015 |
Category: |
Documents |
Upload: | ryan-riley |
View: | 268 times |
Download: | 1 times |
F# ON THE WEB
Ryan Riley
Tachyus
AGENDA
Tachyus’ success with F#
Data Access
Web APIs
Handling Exceptions
Managing Builds
Questions
PLATFORMS
ASP.NET Web API hosted in Azure
AngularJS-based SPA providing information to office workers
iOS application for workers in oil fields
WHY F#?
Less code
Get things done faster
Type safety
Expressive syntax
Full .NET compatibility
Active, strong community (small but growing!)
F# AND DATA ACCESS
SEVERAL OPTIONS
DbmlFile and SqlDataConnection (LINQ to SQL)
EdmxFile and SqlEntityConnection (Entity Framework)
SQL Provider
FSharp.Data.SqlClient <- we use this one
FSHARP.DATA.SQLCLIENT
“SQL is the best DSL for working with data”
- Rob Conery, http://www.infoq.com/articles/ORM-Saffron-Conery
F# ON THE WEB
SIMPLEST HTTP APPLICATION
HttpRequestMessage -> HttpResponseMessage
COMPONENT PARTS
Request/Response Methods, URIs, Status Codes
Headers (info on client, server, request type, etc) General, Request, Response, Content
Resources – “anything that has identity”–RFC2396
RESOURCES
GET /item/1
+ POST /item/1
+ PUT /item/1
+ DELETE /item/1
+ OPTIONS /item/1
GET (or POST) /
+ /items
+ /item/{itemId}
+ /setresult?foo=bar
HTTP Resource
HTTP “Service”
WHERE DOES F# SHINE?
Serve functional Web APIs
Consume HTTP with pattern matching
FRANK
F# DSL using System.Net.Http
Headers composition
Follows the natural composition of HTTP
Frank Resources == HTTP Resources
Define your own conventions!
SIMPLEST HTTP APPLICATION
HttpRequestMessage -> HttpResponseMessage
HttpRequestMessage -> Async<HttpResponseMessage>
DEFINE A METHOD HANDLER
// handler
let echo request = async {
let! body = request.Content.AsyncReadAsString()
return request.CreateResponse(HttpStatusCode.OK, body)
}
// method handler
get echo
DEFINE A RESOURCE
let helloworld request = async { … }
let echo request = async { … }
let resource = route “/” (get helloworld <|> post echo)
DEFINE AN APPLICATION
let todoListResource = route “/” (get todoList <|> …)
let todoItemResource = route “/item/{1}” (put …)
config |> register [todoListResource;todoItemResource]
F# AND ASP.NET
Works out of the box using a F# library and C# web project
F# MVC 5 project template
Frank
F# AND EXCEPTIONS
RAILWAY-ORIENTED PROGRAMMING http://www.slideshare.net/ScottWlaschin/railway-oriented-
programming
http://fsharpforfunandprofit.com/posts/recipe-part2/
F# AND BUILDS
“FAKE is a Domain Specific Language that you can use without knowing F#, but if and when you outgrow it you can keep heading down the F# road. In all cases you've got all of .NET at your command.”
- Scott Hanselman, http://www.hanselman.com/blog/ExploringFAKEAnFBuildSystemForAllOfNET.aspx
AND MORE!
WebSharper and FunScript – F# -> JavaScript compilers
VegaHub – interactive charting from the F# interactive window
F# Web Stack – OWIN-based tools for building web APIs
Work in progress to merge Frank + HyperF + Dyfrig + Taliesin
RESOURCES
F# Software Foundation
Community for F#
Sergey Tihon’s F# Weekly
F# for Fun and Profit
Real World Functional Programming on MSDN
QUESTIONS