F# on the Web

818 views

Published on

Look at building web APIs with F# using ASP.NET Web API and the FSharp.Data.SqlClient type provider.

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
818
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
8
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • Our back end is all F# using Web API and running in Azure.
    Our two client applications started in languages native to their target platforms.
    The iOS team has almost completed a successful conversion to F# using Xamarin.
    We are currently evaluating options to do the same with F# to generate JavaScript and HTML, which should also provide some additional opportunities for code sharing.
  • I know this is called F# on the web, but really, you want to expose some data, right?
    Also, F# is very strong at modeling data flows, so it only makes sense to start at the data layer.
  • Spaghetti code?
    Not this! It’s fully type-checked!
    And it generates the types for you, with the same runtime performance as Dapper and other micro ORMs.
  • Demo!
  • Exceptions can be a real pain in the neck.
    Exceptions tend to bubble back up, requiring you to break all the nice forward-only flows we’ve been writing to this point.
    Railway-oriented (or data flow) programming can help resolve the issue and retain the nice flows we are using.
    The Async module includes a Catch function that will allow us to partition the changes coming out and handle successes and failures as we progress.
  • F# on the Web

    1. 1. Ryan Riley Tachyus
    2. 2.  Tachyus’ success with F#  Data Access  Web APIs  Handling Exceptions  Managing Builds  Questions
    3. 3.  ASP.NET Web API hosted in Azure  AngularJS-based SPA providing information to office workers  iOS application for workers in oil fields
    4. 4.  Less code  Get things done faster  Type safety  Expressive syntax  Full .NET compatibility  Active, strong community (small but growing!)
    5. 5.  DbmlFile and SqlDataConnection (LINQ to SQL)  EdmxFile and SqlEntityConnection (Entity Framework)  SQL Provider  FSharp.Data.SqlClient <- we use this one
    6. 6. “SQL is the best DSL for working with data” - Rob Conery, http://www.infoq.com/articles/ORM-Saffron- Conery
    7. 7. HttpRequestMessage -> HttpResponseMessage
    8. 8. Request/Response  Methods, URIs, Status Codes Headers (info on client, server, request type, etc)  General, Request, Response, Content Resources –  “anything that has identity”–RFC2396
    9. 9. 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”
    10. 10.  Serve functional Web APIs  Consume HTTP with pattern matching
    11. 11.  F# DSL using System.Net.Http  Headers composition  Follows the natural composition of HTTP  Frank Resources == HTTP Resources  Define your own conventions!
    12. 12. HttpRequestMessage -> HttpResponseMessage HttpRequestMessage -> Async<HttpResponseMessage>
    13. 13. // handler let echo request = async { let! body = request.Content.AsyncReadAsString() return request.CreateResponse(HttpStatusCode.OK, body) } // method handler get echo
    14. 14. let helloworld request = async { … } let echo request = async { … } let resource = route “/” (get helloworld <|> post echo)
    15. 15. let todoListResource = route “/” (get todoList <|> …) let todoItemResource = route “/item/{1}” (put …) config |> register [todoListResource;todoItemResource]
    16. 16.  Works out of the box using a F# library and C# web project  F# MVC 5 project template  Frank
    17. 17.  http://www.slideshare.net/ScottWlaschin/railway-oriented- programming  http://fsharpforfunandprofit.com/posts/recipe-part2/
    18. 18. “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.asp x
    19. 19.  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
    20. 20.  F# Software Foundation  Community for F#  Sergey Tihon’s F# Weekly  F# for Fun and Profit  Real World Functional Programming on MSDN

    ×