Path module
Before we move on to defining views for the rest of the application, let's introduce one more file - Path.fs
and insert it before View.fs
(follow same steps as when we added View.fs
):
Path.fs
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: |
|
The module will contain all valid routes in our application.
We'll keep them here in one place, in order to be able to reuse both in App
and View
modules.
Thanks to that, we will minimize the risk of a typo in our View
module.
We defined a submodule called Store
in order to group routes related to one functionality - later in the tutorial we'll have a few more submodules, each of them reflecting a specific set of functionality of the application.
The IntPath
type alias that we declared will let us use our routes in conjunction with static-typed Suave routes (pathScan
in App
module).
We don't need to fully understand the signature of this type, for now we can think of it as a route parametrized with integer value.
And indeed, we annotated the details
route with this type, so that the compiler treats this value specially.
We'll see in a moment how we can use details
in App
and View
modules, with the advantage of static typing.
Let's use the routes from Path
module in our App
:
App.fs
16: 17: 18: 19: 20: 21: 22: 23: |
|
as well as in our View
for aHref
to home
:
View.fs
12: 13: 14: 15: 16: |
|
Note, that in App
module we still benefit from the static typed routes feature that Suave gives us - the id
parameter is inferred by the compiler to be of integer type.
If you're not familiar with type inference mechanism, you can follow up this link.
Full name: SuaveMusicStore.Path.IntPath
type PrintfFormat<'Printer,'State,'Residue,'Result> =
new : value:string -> PrintfFormat<'Printer,'State,'Residue,'Result>
member Value : string
Full name: Microsoft.FSharp.Core.PrintfFormat<_,_,_,_>
--------------------
type PrintfFormat<'Printer,'State,'Residue,'Result,'Tuple> =
inherit PrintfFormat<'Printer,'State,'Residue,'Result>
new : value:string -> PrintfFormat<'Printer,'State,'Residue,'Result,'Tuple>
Full name: Microsoft.FSharp.Core.PrintfFormat<_,_,_,_,_>
--------------------
new : value:string -> PrintfFormat<'Printer,'State,'Residue,'Result>
--------------------
new : value:string -> PrintfFormat<'Printer,'State,'Residue,'Result,'Tuple>
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<_>
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = System.String
Full name: Microsoft.FSharp.Core.string
Full name: Microsoft.FSharp.Core.unit
Full name: SuaveMusicStore.Path.home
from SuaveMusicStore.Path
Full name: SuaveMusicStore.Path.Store.overview
Full name: SuaveMusicStore.Path.Store.browse
Full name: SuaveMusicStore.Path.Store.details
from Suave
Full name: SuaveMusicStore.View.index
Full name: Suave.Html.html
Full name: Suave.Html.head
Full name: Suave.Html.title
Full name: Suave.Html.body
Full name: Suave.Html.div
Full name: Suave.Html.tag
Full name: Suave.Html.a
from SuaveMusicStore
Full name: Suave.Html.htmlToString
from SuaveMusicStore
from Suave
from Suave
from Suave
from Suave
from Suave
Full name: SuaveMusicStore.App.browse
Full name: Suave.Http.request
Full name: Suave.Successful.OK
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.sprintf
Full name: Suave.RequestErrors.BAD_REQUEST
Full name: SuaveMusicStore.App.webPart
Full name: Suave.WebPart.choose
Full name: Suave.Filters.path
from SuaveMusicStore
Full name: Suave.Filters.pathScan
Full name: SuaveMusicStore.Path.Store.details
Full name: Suave.Web.startWebServer
Full name: Suave.Web.defaultConfig
Show code from this section on GitHub