SlideShare ist ein Scribd-Unternehmen logo
1 von 36
The Functional Web
Ryan Riley
O Logos Bible Software
O Community for F#
O F# MVP
O OSS: FSharpx, Fracture, Frank
O @panesofglass
Outline
O The State of HTTP on .NET
O Composition Patterns in HTTP
O Identifying Problems
O Examining a Solution
The State of HTTP on .NET
Current Options
O http.sys
  O HttpListener
  O IIS (IHttpModule & IHttpHandler)
     O Web Forms
     O MVC
  O WCF HTTP & Data Services
Future Options
O System.Net.Http (BETA)
  O .NET 4.5
  O Available on NuGet
O ASP.NET Web API (BETA)
  O Builds on System.Net.Http
  O Integrated with MVC 4
OSS Options
    Frameworks           Servers
O   FubuMVC            O Firefly (OWIN)
O   MonoRail           O Fracture (F#)
O   NancyFx
                       O Kayak (OWIN)
O   OpenRasta
                       O Manos de Mono
O   OWIN/Gate
O   ServiceStack.NET   O Mono XSP
O   WebSharper
O   
 and many more!
Composition Patterns in
       HTTP
Component Parts
O Request/Response Lines
  O Methods, URIs, Status Codes
O Headers
  O General, Request, Response, Content
O Resources
O Representations
O Hypermedia
Simplest HTTP Application

  HttpRequestMessage -> HttpResponseMessage
Resources
GET /item/1
+ POST /item/1
+ PUT /item/1
+ OPTIONS /item/1
=
Resource at / with GET, POST, PUT, &
OPTIONS
HTTP Applications
/
+ /items
+ /item/{itemId}
+ /help
=
Typical HTTP “application”
Content Negotiation
Client Accepts              Server Supports
application/xml;q=0.9       application/json
application/json;q=0.8      text/plain
text/plain;q=0.5            text/html


                  application/json
Identifying Problems
HttpListener
O Low-level
O Defines the signature for a single application only
O HttpListenerContext provides a singleton; no
  chance to intercept and chain behavior
O Routing requests requires custom handling;
  typically by using imperative if-then-else
O No means of chaining or composing multiple
  listeners
HttpListener
HttpListener.Start
 ("http://localhost:8082/", (fun (request, response) -> async {
  match request.Url.LocalPath with
| "/post" ->
// Send message to the chat room
      room.SendMessage(request.InputString)
      response.Reply("OK")
  | "/chat" ->
      // Get messages from the chat room (asynchronously!)
      let! text = room.AsyncGetContent()
      response.Reply(text)
  | s ->
      // Handle an ordinary file request
      let file =
         root + (if s = "/" then "chat.html" else s.ToLower())
      if File.Exists(file) then
         let typ = contentTypes.[Path.GetExtension(file)]
         response.Reply(typ, File.ReadAllBytes(file))
      else
         response.Reply(sprintf "File not found: %s" file) }),
cts.Token)
IHttpModule & IHttpHandler
O Low-level
O HttpContext has the same problems as
  HttpListenerContext
O IHttpHandler could represent a Resource, but
  method mapping is imperative
O IHttpModule provides a middleware layer for
  routing or hosting multiple IHttpHandlers
O System.Web.Routing surfaces the routing
  component
IHttpModule & IHttpHandler
interface IHttpModule
{
    void Dispose();
    void Init(HttpApplication context);
}

interface IHttpHandler
{
    bool IsReusable { get; }
    void ProcessRequest(HttpContext context);
}
ASP.NET Web Forms
O HTML composition via
    MasterPages, Pages, and Controls
O   Suffers many problems associated with
    IHttpModule and IHttpHandler
O   Evented model allows for interception
O   No built-in support for other representations
O   Pages loosely correlate to Resources
O   Application composition and routing by file
    path
ASP.NET MVC
O Suffers many problems associated with
  IHttpModule and IHttpHandler
O Primarily HTML generation but allows for better
  HTTP control
O Built-in support for handling Ajax requests
O ActionFilters allow for behavior composition at
  different points:
  Authorize, ActionExecuting, ActionExecuted, Resul
  tExecuting, ResultExecuted
ASP.NET MVC, cont.
O Content Negotiation is still very manual
O ViewEngines and Serializers can be made to
  render various representations
O ViewEngines offer representation composition
O Controllers ~ Resources, but not quite
O Areas and Routing allow for Nested
  Resources, to a degree
Problem Summary
O Have:
  O Limited interception for cross-cutting
    concerns
  O Representation composition
O Do not have:
  O No easy resource composition
  O No built-in content negotiation
Composition for Conneg
O Rendering
  O Imperative if-then-else
  O Serializers
O Location
  O Within the specific method handler (common for
    imperative)
  O Top-level (common for serializers)
O Why not both?
Nested Resources
O   Imperative if-then-else
O   Routing
O   MVC Areas offer another level
O   What about more than one level?
    O Rails – problem with deep URIs
    O System.Web.Routing does everything at the
      top-level, so tracking deeper resource trees is
      difficult.
Examining a Solution
Function Composition
O Functional programming offers solutions
 to these problems
  O Filter
  O Map
  O Reduce
Frank
O 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!
Simplest HTTP Frank
    Application
   HttpRequestMessage -> HttpResponseMessage

HttpRequestMessage -> Async<HttpResponseMessage>
Define a Method Handler
// handler
let echo request = async {
  let! body = request.Content.AsyncReadAsString()
  return HttpResponseMessage.ReplyTo(request, 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 
)

let app = merge [ todoListResource; todoItemResource ]
Leverage Conneg
val negotiateMediaType = formatters ->
                         HttpRequestMessage ->
                         string ->
                         Async<HttpResponseMessage>

let echo = negotiateMediaType formatters
      <| fun request ->
                request.Content.AsyncReadAsString())
WebSharper
O One language for both client and server
O Can leverage to cleanly separate parts
O Use WebSharper to generate code-on-
  demand to send to the client
O Plays well with existing tools
Summary
Resources
O 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
Thank you!
O Please rate this talk:
  http://speakerrate.com/talks/9293-the-
  functional-web

Weitere Àhnliche Inhalte

Was ist angesagt?

#Pharo Days 2016 Reflectivity
#Pharo Days 2016 Reflectivity#Pharo Days 2016 Reflectivity
#Pharo Days 2016 ReflectivityPhilippe Back
 
PHP BASIC PRESENTATION
PHP BASIC PRESENTATIONPHP BASIC PRESENTATION
PHP BASIC PRESENTATIONkrutitrivedi
 
Github.com anton terekhov-orientdb-php
Github.com anton terekhov-orientdb-phpGithub.com anton terekhov-orientdb-php
Github.com anton terekhov-orientdb-phpSan jay
 
Impala: A Modern, Open-Source SQL Engine for Hadoop
Impala: A Modern, Open-Source SQL Engine for HadoopImpala: A Modern, Open-Source SQL Engine for Hadoop
Impala: A Modern, Open-Source SQL Engine for HadoopAll Things Open
 
Building Awesome APIs with Lumen
Building Awesome APIs with LumenBuilding Awesome APIs with Lumen
Building Awesome APIs with LumenKit Brennan
 
Fluentd meetup dive into fluent plugin (outdated)
Fluentd meetup dive into fluent plugin (outdated)Fluentd meetup dive into fluent plugin (outdated)
Fluentd meetup dive into fluent plugin (outdated)N Masahiro
 
JavaOne 2009 - TS-5276 - RESTful Protocol Buffers
JavaOne 2009 - TS-5276 - RESTful  Protocol BuffersJavaOne 2009 - TS-5276 - RESTful  Protocol Buffers
JavaOne 2009 - TS-5276 - RESTful Protocol BuffersMatt O'Keefe
 
Web Development Course: PHP lecture 3
Web Development Course: PHP lecture 3Web Development Course: PHP lecture 3
Web Development Course: PHP lecture 3Gheyath M. Othman
 
ASP.NET WEB API
ASP.NET WEB APIASP.NET WEB API
ASP.NET WEB APIThang Chung
 
What Is Php
What Is PhpWhat Is Php
What Is PhpAVC
 
Client Side Technologies
Client Side TechnologiesClient Side Technologies
Client Side TechnologiesAnirban Majumdar
 
03 form-data
03 form-data03 form-data
03 form-datasnopteck
 

Was ist angesagt? (20)

#Pharo Days 2016 Reflectivity
#Pharo Days 2016 Reflectivity#Pharo Days 2016 Reflectivity
#Pharo Days 2016 Reflectivity
 
PHP BASIC PRESENTATION
PHP BASIC PRESENTATIONPHP BASIC PRESENTATION
PHP BASIC PRESENTATION
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
httpie
httpiehttpie
httpie
 
Php
PhpPhp
Php
 
Github.com anton terekhov-orientdb-php
Github.com anton terekhov-orientdb-phpGithub.com anton terekhov-orientdb-php
Github.com anton terekhov-orientdb-php
 
Impala: A Modern, Open-Source SQL Engine for Hadoop
Impala: A Modern, Open-Source SQL Engine for HadoopImpala: A Modern, Open-Source SQL Engine for Hadoop
Impala: A Modern, Open-Source SQL Engine for Hadoop
 
Building Awesome APIs with Lumen
Building Awesome APIs with LumenBuilding Awesome APIs with Lumen
Building Awesome APIs with Lumen
 
Fluentd meetup dive into fluent plugin (outdated)
Fluentd meetup dive into fluent plugin (outdated)Fluentd meetup dive into fluent plugin (outdated)
Fluentd meetup dive into fluent plugin (outdated)
 
PHP Tutorials
PHP TutorialsPHP Tutorials
PHP Tutorials
 
Php introduction
Php introductionPhp introduction
Php introduction
 
JavaOne 2009 - TS-5276 - RESTful Protocol Buffers
JavaOne 2009 - TS-5276 - RESTful  Protocol BuffersJavaOne 2009 - TS-5276 - RESTful  Protocol Buffers
JavaOne 2009 - TS-5276 - RESTful Protocol Buffers
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
Web Development Course: PHP lecture 3
Web Development Course: PHP lecture 3Web Development Course: PHP lecture 3
Web Development Course: PHP lecture 3
 
ASP.NET WEB API
ASP.NET WEB APIASP.NET WEB API
ASP.NET WEB API
 
PHP slides
PHP slidesPHP slides
PHP slides
 
What Is Php
What Is PhpWhat Is Php
What Is Php
 
Tml for Laravel
Tml for LaravelTml for Laravel
Tml for Laravel
 
Client Side Technologies
Client Side TechnologiesClient Side Technologies
Client Side Technologies
 
03 form-data
03 form-data03 form-data
03 form-data
 

Ähnlich wie The Functional Web

Networked APIs with swift
Networked APIs with swiftNetworked APIs with swift
Networked APIs with swiftTim Burks
 
Web Server and how we can design app in C#
Web Server and how we can design app  in C#Web Server and how we can design app  in C#
Web Server and how we can design app in C#caohansnnuedu
 
jkljklj
jkljkljjkljklj
jkljkljhoefo
 
Web forms and server side scripting
Web forms and server side scriptingWeb forms and server side scripting
Web forms and server side scriptingsawsan slii
 
F# on the Web
F# on the WebF# on the Web
F# on the WebRyan Riley
 
Automating the Use of Web APIs through Lightweight Semantics
Automating the Use of Web APIs through Lightweight SemanticsAutomating the Use of Web APIs through Lightweight Semantics
Automating the Use of Web APIs through Lightweight Semanticsmmaleshkova
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015Nir Noy
 
Web Services 2009
Web Services 2009Web Services 2009
Web Services 2009Cathie101
 
Web Services 2009
Web Services 2009Web Services 2009
Web Services 2009Cathie101
 
REST, JSON and RSS with WCF 3.5
REST, JSON and RSS with WCF 3.5REST, JSON and RSS with WCF 3.5
REST, JSON and RSS with WCF 3.5Rob Windsor
 
ASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsIdo Flatow
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1vikram singh
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiTiago Knoch
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST APIAniruddh Bhilvare
 
F# on the Server-Side
F# on the Server-SideF# on the Server-Side
F# on the Server-SideTomas Petricek
 

Ähnlich wie The Functional Web (20)

ASP.NET WEB API Training
ASP.NET WEB API TrainingASP.NET WEB API Training
ASP.NET WEB API Training
 
Networked APIs with swift
Networked APIs with swiftNetworked APIs with swift
Networked APIs with swift
 
Web Server and how we can design app in C#
Web Server and how we can design app  in C#Web Server and how we can design app  in C#
Web Server and how we can design app in C#
 
jkljklj
jkljkljjkljklj
jkljklj
 
Web forms and server side scripting
Web forms and server side scriptingWeb forms and server side scripting
Web forms and server side scripting
 
Servlet by Rj
Servlet by RjServlet by Rj
Servlet by Rj
 
Servlet basics
Servlet basicsServlet basics
Servlet basics
 
F# on the Web
F# on the WebF# on the Web
F# on the Web
 
Automating the Use of Web APIs through Lightweight Semantics
Automating the Use of Web APIs through Lightweight SemanticsAutomating the Use of Web APIs through Lightweight Semantics
Automating the Use of Web APIs through Lightweight Semantics
 
Servlet & jsp
Servlet  &  jspServlet  &  jsp
Servlet & jsp
 
Webtechnologies
Webtechnologies Webtechnologies
Webtechnologies
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015
 
Web Services 2009
Web Services 2009Web Services 2009
Web Services 2009
 
Web Services 2009
Web Services 2009Web Services 2009
Web Services 2009
 
REST, JSON and RSS with WCF 3.5
REST, JSON and RSS with WCF 3.5REST, JSON and RSS with WCF 3.5
REST, JSON and RSS with WCF 3.5
 
ASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP Fundamentals
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
F# on the Server-Side
F# on the Server-SideF# on the Server-Side
F# on the Server-Side
 

Mehr von Ryan Riley

A Brief History of OWIN
A Brief History of OWINA Brief History of OWIN
A Brief History of OWINRyan Riley
 
Test first
Test firstTest first
Test firstRyan Riley
 
Introduction to F#x
Introduction to F#xIntroduction to F#x
Introduction to F#xRyan Riley
 
Rx workshop
Rx workshopRx workshop
Rx workshopRyan Riley
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional ProgrammingRyan Riley
 
Practical F#
Practical F#Practical F#
Practical F#Ryan Riley
 
HTTP: the Other ESB
HTTP: the Other ESBHTTP: the Other ESB
HTTP: the Other ESBRyan Riley
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignRyan Riley
 

Mehr von Ryan Riley (8)

A Brief History of OWIN
A Brief History of OWINA Brief History of OWIN
A Brief History of OWIN
 
Test first
Test firstTest first
Test first
 
Introduction to F#x
Introduction to F#xIntroduction to F#x
Introduction to F#x
 
Rx workshop
Rx workshopRx workshop
Rx workshop
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 
Practical F#
Practical F#Practical F#
Practical F#
 
HTTP: the Other ESB
HTTP: the Other ESBHTTP: the Other ESB
HTTP: the Other ESB
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 

KĂŒrzlich hochgeladen

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...gurkirankumar98700
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel AraĂșjo
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

KĂŒrzlich hochgeladen (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

The Functional Web

  • 2. Ryan Riley O Logos Bible Software O Community for F# O F# MVP O OSS: FSharpx, Fracture, Frank O @panesofglass
  • 3. Outline O The State of HTTP on .NET O Composition Patterns in HTTP O Identifying Problems O Examining a Solution
  • 4. The State of HTTP on .NET
  • 5. Current Options O http.sys O HttpListener O IIS (IHttpModule & IHttpHandler) O Web Forms O MVC O WCF HTTP & Data Services
  • 6. Future Options O System.Net.Http (BETA) O .NET 4.5 O Available on NuGet O ASP.NET Web API (BETA) O Builds on System.Net.Http O Integrated with MVC 4
  • 7. OSS Options Frameworks Servers O FubuMVC O Firefly (OWIN) O MonoRail O Fracture (F#) O NancyFx O Kayak (OWIN) O OpenRasta O Manos de Mono O OWIN/Gate O ServiceStack.NET O Mono XSP O WebSharper O 
 and many more!
  • 9. Component Parts O Request/Response Lines O Methods, URIs, Status Codes O Headers O General, Request, Response, Content O Resources O Representations O Hypermedia
  • 10. Simplest HTTP Application HttpRequestMessage -> HttpResponseMessage
  • 11. Resources GET /item/1 + POST /item/1 + PUT /item/1 + OPTIONS /item/1 = Resource at / with GET, POST, PUT, & OPTIONS
  • 12. HTTP Applications / + /items + /item/{itemId} + /help = Typical HTTP “application”
  • 13. Content Negotiation Client Accepts Server Supports application/xml;q=0.9 application/json application/json;q=0.8 text/plain text/plain;q=0.5 text/html application/json
  • 15. HttpListener O Low-level O Defines the signature for a single application only O HttpListenerContext provides a singleton; no chance to intercept and chain behavior O Routing requests requires custom handling; typically by using imperative if-then-else O No means of chaining or composing multiple listeners
  • 16. HttpListener HttpListener.Start ("http://localhost:8082/", (fun (request, response) -> async { match request.Url.LocalPath with | "/post" -> // Send message to the chat room room.SendMessage(request.InputString) response.Reply("OK") | "/chat" -> // Get messages from the chat room (asynchronously!) let! text = room.AsyncGetContent() response.Reply(text) | s -> // Handle an ordinary file request let file = root + (if s = "/" then "chat.html" else s.ToLower()) if File.Exists(file) then let typ = contentTypes.[Path.GetExtension(file)] response.Reply(typ, File.ReadAllBytes(file)) else response.Reply(sprintf "File not found: %s" file) }), cts.Token)
  • 17. IHttpModule & IHttpHandler O Low-level O HttpContext has the same problems as HttpListenerContext O IHttpHandler could represent a Resource, but method mapping is imperative O IHttpModule provides a middleware layer for routing or hosting multiple IHttpHandlers O System.Web.Routing surfaces the routing component
  • 18. IHttpModule & IHttpHandler interface IHttpModule { void Dispose(); void Init(HttpApplication context); } interface IHttpHandler { bool IsReusable { get; } void ProcessRequest(HttpContext context); }
  • 19. ASP.NET Web Forms O HTML composition via MasterPages, Pages, and Controls O Suffers many problems associated with IHttpModule and IHttpHandler O Evented model allows for interception O No built-in support for other representations O Pages loosely correlate to Resources O Application composition and routing by file path
  • 20. ASP.NET MVC O Suffers many problems associated with IHttpModule and IHttpHandler O Primarily HTML generation but allows for better HTTP control O Built-in support for handling Ajax requests O ActionFilters allow for behavior composition at different points: Authorize, ActionExecuting, ActionExecuted, Resul tExecuting, ResultExecuted
  • 21. ASP.NET MVC, cont. O Content Negotiation is still very manual O ViewEngines and Serializers can be made to render various representations O ViewEngines offer representation composition O Controllers ~ Resources, but not quite O Areas and Routing allow for Nested Resources, to a degree
  • 22. Problem Summary O Have: O Limited interception for cross-cutting concerns O Representation composition O Do not have: O No easy resource composition O No built-in content negotiation
  • 23. Composition for Conneg O Rendering O Imperative if-then-else O Serializers O Location O Within the specific method handler (common for imperative) O Top-level (common for serializers) O Why not both?
  • 24. Nested Resources O Imperative if-then-else O Routing O MVC Areas offer another level O What about more than one level? O Rails – problem with deep URIs O System.Web.Routing does everything at the top-level, so tracking deeper resource trees is difficult.
  • 26. Function Composition O Functional programming offers solutions to these problems O Filter O Map O Reduce
  • 27. Frank O 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!
  • 28. Simplest HTTP Frank Application HttpRequestMessage -> HttpResponseMessage HttpRequestMessage -> Async<HttpResponseMessage>
  • 29. Define a Method Handler // handler let echo request = async { let! body = request.Content.AsyncReadAsString() return HttpResponseMessage.ReplyTo(request, body) } // method handler get echo
  • 30. Define a Resource let helloworld request = async { 
 } let echo request = async { 
 } let resource = route “/” (get helloworld <|> post echo)
  • 31. Define an Application let todoListResource = route “/” (get todoList <|> 
) let todoItemResource = route “/item/{1}” (put 
) let app = merge [ todoListResource; todoItemResource ]
  • 32. Leverage Conneg val negotiateMediaType = formatters -> HttpRequestMessage -> string -> Async<HttpResponseMessage> let echo = negotiateMediaType formatters <| fun request -> request.Content.AsyncReadAsString())
  • 33. WebSharper O One language for both client and server O Can leverage to cleanly separate parts O Use WebSharper to generate code-on- demand to send to the client O Plays well with existing tools
  • 35. Resources O 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
  • 36. Thank you! O Please rate this talk: http://speakerrate.com/talks/9293-the- functional-web

Hinweis der Redaktion

  1. HTTP defines several components that allow distributed, loosely-coupled agents to communicate. The first lines of requests and responses are standardized to ensure that loosely-coupled components can understand one another, yet they allow for extension either by standards bodies or for internal, proprietary use.
  2. This may be new to some, but this resource is not the same as the collection of items at /items.
  3. The aggregate of many resources is generally what we refer to as an HTTP, or Web, Application. A single resource is enough, as is a single method.
  4. Resources may be directly returned in a response. In the beginning, when most HTTP applications served static files, this was common. However, Resources are not equivalent to the representation returned to the client, even if they appear identical. Unlike editing files locally, if you were to edit a file returned from an HTTP application, you would not be editing the original file. You would need to re-submit the file to the server, if allowed, and then the server would need to take the content you supplied and update the original Resource.It is thus reasonable to understand that a Resource can be represented in more than one way. A JSON representation is just as valid as XML, HTML, or even an image.Content negotiation, or “conneg,” is a cross-cutting concern that allows HTTP applications to select an appropriate representation to send in the response message. The actual execution of this selection could occur either at the top-level or at the lowest-level of a composed HTTP application.
  5. It’s also important to note that the request and response headers are just NameValueCollections, so you don’t have easy, typed access to common header values. This isn’t critical for composition but odd for a statically-typed language platform.DEMO: In spite of its short-comings, you can still do some interesting things with HttpListener. Tomas Petricek created a really interesting project where he uses HttpListener as the base for a chat server.
  6. It’s also important to note that the request and response headers are just NameValueCollections, so you don’t have easy, typed access to common header values. This isn’t critical for composition but odd for a statically-typed language platform.DEMO: In spite of its short-comings, you can still do some interesting things with HttpListener. Tomas Petricek created a really interesting project where he uses HttpListener as the base for a chat server.
  7. It’s important to note here that these interfaces are exposed by IIS and can be used to modify that server directly, though they are also tied directly to that server. Mono offers additional options for hosting, but you should understand that you are generally tied to IIS.
  8. It’s important to note here that these interfaces are exposed by IIS and can be used to modify that server directly, though they are also tied directly to that server. Mono offers additional options for hosting, but you should understand that you are generally tied to IIS.
  9. ASP.NET Web Forms 4.0 provided a hook intoSystem.Web.Routing.Also of note:Web Forms has historically been demonized by it’s poor HTML output, requiring a &lt;form&gt; element to scope control usage.Many server controls have weird behavior. Anchor tags, which generally perform GET requests instead POST back to server, even just to navigate to another page. Some of this is of course avoidable, but the designer-centric focus often leads to ill-advised HTTP use.FSharpCodeDomProvider has limitations.
  10. Also difficult to use F# for View Models. You will have a difficult time using records and discriminated unions as types, and you’ll be forced into mutability.
  11. Current frameworks typically choose to lean on one or the other of the above sets of options. However, there really should be no reason to require only one or the other. In fact, you should be free to define various boundaries where you might use a serializer approach over a subset of resources.
  12. Routing is nothing more than filtering down a set of handlers to select the appropriate one and return a response.A Response is nothing more than a map function over a request, though it is true that some HTTP methods are destructive (e.g. POST).Pulling handlers into resources or applications is nothing more than a reduce function. Frank uses merge; WebSharper uses Sum.
  13. For those with a stronger bent towards building web sites, Mauricio Scheffer’s Figment may be a closer match to your taste.
  14. Compare the Frank application signature with the simplest app signature we used above. The only addition is that we are stating that an application is non-blocking. This is the same idea as is used in node.js. It’s also sort-of required since Frank sits on System.Net.Http via MessageHandlers. The signature for the MessageHandler.SendAsync is the same but for Task rather than Async. This signature extends all the way through all layers of composition.
  15. A resource is the only current location that does not conform solely to the Frank application signature. A resource holds both a Uri Template (its name) as well as a HttpRequestMessage -&gt; Async&lt;HttpResponseMessage&gt; option. Why the option? The resource will respond with a 405 Method Not Allowed if it does not respond to the method thrown its way. Thus the option allows the programmer to define the methods for the resource without having to manually hook up the 405 response.
  16. Similar to resource, merge is a function of HttpRequestMessage -&gt; Async&lt;HttpResponseMessage&gt; option. When a resource uri is not found, a 404 Not Found response is returned. The result, however, is a Frank application.
  17. Frank currently uses Mauricio Scheffer’sFsConneg library, now in FSharpx.Http. System.Net.Http has a similar mechanism, but it’s currently still a little heavy as they work out the kinks in preparation for the RC. FsConneg provides a mechanism for submitting the Accept headers and a list of supported formats and returns the best match. negotiateMediaType wraps that with the selection of the appropriate formatter, of type System.Net.Http.Formatting.MediaTypeFormatter, and returns the formatted content.
  18. Another option is Pit FW, which was featured on the Community for F# on 2/21/2012 (today). It also compiles F# to JavaScript. You can learn more at http://pitfw.org/.
  19. Using F# for web projects isn’t just about code size. Yes, you’ll save some lines of code, but more importantly, you’ll work closer to the guts of HTTP. You can leverage the power of composition to build applications that will be more maintainable and much clearer to understand.