RouteProvider


Configuration:

1: 
type Dummy = IsakSky.RouteProvider<"MyRoutes", routes, false, false, "MyRoutes.fs">

Generated code:

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
44: 
45: 
46: 
47: 
48: 
49: 
50: 
51: 
52: 
53: 
54: 
55: 
56: 
57: 
58: 
59: 
60: 
61: 
62: 
63: 
64: 
65: 
66: 
67: 
68: 
69: 
70: 
71: 
72: 
73: 
74: 
75: 
76: 
77: 
78: 
79: 
80: 
81: 
82: 
83: 
84: 
85: 
86: 
87: 
88: 
89: 
90: 
91: 
92: 
// Generated by RouteProvider 0.0.0.0
namespace MyNamespace

open System
module MyModule =
  let getProject (projectId:int64) =
      "projects/" + projectId.ToString()
  let getProjectComments (projectId:int64) (commentId:int64) =
      "projects/" + projectId.ToString() + "comments/" + commentId.ToString()
  let updateProject (projectId:int) =
      "projects/" + projectId.ToString()
  let GET__projects_statistics  =
      "projects/statistics/"
  let getPerson (name:string) =
      "people/" + name

  module Internal =
    let fakeBaseUri = new Uri("http://a.a")

    exception RouteNotMatchedException of string * string

  type MyRoutes =
    { getProject: int64->unit
      getProjectComments: int64->int64->unit
      updateProject: int->unit
      GET__projects_statistics: unit->unit
      getPerson: string->unit
      notFound: (string->string->unit) option }

    member inline private this.HandleNotFound(verb, path) =
      match this.notFound with
      | None -> raise (Internal.RouteNotMatchedException (verb, path))
      | Some(notFound) -> notFound verb path

    member this.DispatchRoute(verb:string, path:string) : unit =
      let parts = path.Split('/')
      let start = if parts.[0] = "" then 1 else 0
      let endOffset = if parts.Length > 0 && parts.[parts.Length - 1] = "" then 1 else 0
      match parts.Length - start - endOffset with
      | 4 ->
        if String.Equals(parts.[0 + start],"projects") then
          let mutable projectId = 0L
          if Int64.TryParse(parts.[1 + start], &projectId) then
            if String.Equals(parts.[2 + start],"comments") then
              let mutable commentId = 0L
              if Int64.TryParse(parts.[3 + start], &commentId) then
                if verb = "GET" then this.getProjectComments projectId commentId
                else this.HandleNotFound(verb, path)
              else this.HandleNotFound(verb, path)
            else this.HandleNotFound(verb, path)
          else this.HandleNotFound(verb, path)
        else this.HandleNotFound(verb, path)
      | 2 ->
        if String.Equals(parts.[0 + start],"people") then
          if verb = "GET" then this.getPerson (parts.[1 + start])
          else this.HandleNotFound(verb, path)
        elif String.Equals(parts.[0 + start],"projects") then
          let mutable int64ArgDepth_1 = 0L
          let mutable intArgDepth_1 = 0
          if String.Equals(parts.[1 + start],"statistics") then
            if verb = "GET" then this.GET__projects_statistics()
            else this.HandleNotFound(verb, path)
          elif Int64.TryParse(parts.[1 + start], &int64ArgDepth_1) then
            if verb = "GET" then this.getProject int64ArgDepth_1
            else this.HandleNotFound(verb, path)
          elif Int32.TryParse(parts.[1 + start], &intArgDepth_1) then
            if verb = "PUT" then this.updateProject intArgDepth_1
            else this.HandleNotFound(verb, path)
          else this.HandleNotFound(verb, path)
        else this.HandleNotFound(verb, path)
      | _ ->
        this.HandleNotFound(verb, path)

    member this.DispatchRoute(verb:string, uri:Uri) : unit =
      // Ensure we have an Absolute Uri, or just about every method on Uri chokes
      let uri = if uri.IsAbsoluteUri then uri else new Uri(Internal.fakeBaseUri, uri)
      let path = uri.GetComponents(UriComponents.Path, UriFormat.Unescaped)
      this.DispatchRoute(verb, path)

    static member Router(
      getProject: int64->unit,
      getProjectComments: int64->int64->unit,
      updateProject: int->unit,
      GET__projects_statistics: unit->unit,
      getPerson: string->unit,
      ?notFound: string->string->unit) : MyRoutes =
      { getProject = getProject
        getProjectComments = getProjectComments
        updateProject = updateProject
        GET__projects_statistics = GET__projects_statistics
        getPerson = getPerson
        notFound = notFound}
namespace System
Multiple items
val int64 : value:'T -> int64 (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int64

--------------------
type int64 = System.Int64

Full name: Microsoft.FSharp.Core.int64

--------------------
type int64<'Measure> = int64

Full name: Microsoft.FSharp.Core.int64<_>
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
type unit = Unit

Full name: Microsoft.FSharp.Core.unit
type 'T option = Option<'T>

Full name: Microsoft.FSharp.Core.option<_>
union case Option.None: Option<'T>
val raise : exn:System.Exception -> 'T

Full name: Microsoft.FSharp.Core.Operators.raise
union case Option.Some: Value: 'T -> Option<'T>
module String

from Microsoft.FSharp.Core
Fork me on GitHub