Let's move on to configuring a few routes in our application.
Before we do that, we'll need to open up two more modules at the beginning of
1: 2: 3: 4: 5:
Now, let's create a couple of routing rules, so that our application responds with different content for different paths.
To achieve that, we can use the
choose function, which takes a list of WebParts, and chooses the first one that applies (returns
Some), or if none WebPart applies, then choose will also return
7: 8: 9: 10: 11: 12: 13:
path symbol in above snippet to inspect this function's type.
What it means is that if we give it a string, it will return a WebPart.
Under the hood, the function looks at the incoming request and returns
Some if the path matches, and
>=> operator comes also from Suave library. It composes two WebParts into one by first evaluating the WebPart on the left, and applying the WebPart on the right only if the first one returned
After applying the change try out all paths from the snippet by appending them to localhost URL your application is running under.
Full name: SuaveMusicStore.webPart
Full name: Suave.WebPart.choose
Full name: Suave.Filters.path
Full name: Suave.Successful.OK
Full name: Suave.Web.startWebServer
Full name: Suave.Web.defaultConfig
Show code from this section on GitHub