+ All Categories
Home > Documents > F# on the Web

F# on the Web

Date post: 10-May-2015
Category:
Upload: ryan-riley
View: 268 times
Download: 1 times
Share this document with a friend
Description:
Look at building web APIs with F# using ASP.NET Web API and the FSharp.Data.SqlClient type provider.
Popular Tags:
26
F# ON THE WEB Ryan Riley Tachyus
Transcript
Page 1: F# on the Web

F# ON THE WEB

Ryan Riley

Tachyus

Page 2: F# on the Web

AGENDA

Tachyus’ success with F#

Data Access

Web APIs

Handling Exceptions

Managing Builds

Questions

Page 3: F# on the Web

MEASURE, ANALYZE, PRODUCE

Page 4: F# on the Web

PLATFORMS

ASP.NET Web API hosted in Azure

AngularJS-based SPA providing information to office workers

iOS application for workers in oil fields

Page 5: F# on the Web

WHY F#?

Less code

Get things done faster

Type safety

Expressive syntax

Full .NET compatibility

Active, strong community (small but growing!)

Page 6: F# on the Web

F# AND DATA ACCESS

Page 7: F# on the Web

SEVERAL OPTIONS

DbmlFile and SqlDataConnection (LINQ to SQL)

EdmxFile and SqlEntityConnection (Entity Framework)

SQL Provider

FSharp.Data.SqlClient <- we use this one

Page 8: F# on the Web

FSHARP.DATA.SQLCLIENT

“SQL is the best DSL for working with data”

- Rob Conery, http://www.infoq.com/articles/ORM-Saffron-Conery

Page 9: F# on the Web

F# ON THE WEB

Page 10: F# on the Web
Page 11: F# on the Web

SIMPLEST HTTP APPLICATION

HttpRequestMessage -> HttpResponseMessage

Page 12: F# on the Web

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

Page 13: F# on the Web

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”

Page 14: F# on the Web

WHERE DOES F# SHINE?

Serve functional Web APIs

Consume HTTP with pattern matching

Page 15: F# on the Web

FRANK

F# DSL using System.Net.Http

Headers composition

Follows the natural composition of HTTP

Frank Resources == HTTP Resources

Define your own conventions!

Page 16: F# on the Web

SIMPLEST HTTP APPLICATION

HttpRequestMessage -> HttpResponseMessage

HttpRequestMessage -> Async<HttpResponseMessage>

Page 17: F# on the Web

DEFINE A METHOD HANDLER

// handler

let echo request = async {

let! body = request.Content.AsyncReadAsString()

return request.CreateResponse(HttpStatusCode.OK, body)

}

// method handler

get echo

Page 18: F# on the Web

DEFINE A RESOURCE

let helloworld request = async { … }

let echo request = async { … }

let resource = route “/” (get helloworld <|> post echo)

Page 19: F# on the Web

DEFINE AN APPLICATION

let todoListResource = route “/” (get todoList <|> …)

let todoItemResource = route “/item/{1}” (put …)

config |> register [todoListResource;todoItemResource]

Page 20: F# on the Web

F# AND ASP.NET

Works out of the box using a F# library and C# web project

F# MVC 5 project template

Frank

Page 21: F# on the Web

F# AND EXCEPTIONS

Page 22: F# on the Web

RAILWAY-ORIENTED PROGRAMMING http://www.slideshare.net/ScottWlaschin/railway-oriented-

programming

http://fsharpforfunandprofit.com/posts/recipe-part2/

Page 23: F# on the Web

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

Page 24: F# on the Web

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

Page 25: F# on the Web

RESOURCES

F# Software Foundation

Community for F#

Sergey Tihon’s F# Weekly

F# for Fun and Profit

Real World Functional Programming on MSDN

Page 26: F# on the Web

QUESTIONS


Recommended