simonhdickson/Fancy — pull request #2 by albertjan (2014-02-03 15:51:53+00:00)
Title: Making Fancy play a bit more with Nancy

Hi Simon,

First of all awesome work on Fancy we loved it! Second of all I hope you don't mind we changed some stuff around :neckbeard:

We are @remkoboschker and @albertjan and we work at @Curit and we plan to use fancy in the next iteration of our backend.

What did we do:

* We removed the abstract base class. This wasn't really necessary anymore after we
* Removed the state monad which took us a while to understand and after we did we found out we could remove it when we
* Make it possible to access the module *in* the routes so we made the fancy builder take a nancy module which makes it possible to call it in the constructor
* There was an issue with the multiple parameters from the `PrintFormat`. We could fix that because we
* Created the `BoxedAsyncBuilder` making it possible to not specify the type of the processor. Because it always returns an object.

Bare with me :smile:

* Using the `BoxedAsyncBuilder` makes all routes async which seems only logical.
* We added an optional last parameter that if you tell it to be a `CancellationToken` it will become one.
* We added some of the missing verbs.
* We added before and after module pipeline hooks
* We made the regex even less evil
* Removed as much of the reflection as we could.
* Added a `++` operator to make it easier to combine delegates (handy for the after hook)
* startAsPlainTask operator with starts a `Task` not a `Task`
* Updated the test and some docs. (More is needed here)

Here's what how one would use the FancyBuilder now:

```f#

type ExampleModule() as this =
inherit NancyModule() //doing this way we have access to the constructor of the nancy module
//to set the basepath for example. And we can give dependencies, and let the
//IOC inject those for us and use them in the routes.
do fancy this { // won't you? :) this is the parameter to the FancyBuilder the NancyModule
before (fun context cancellationToken -> async {
printf "You're in the before hook"
return null //yeah I know this could be better and I'll look into it.
})
get "/" (fun () -> fancyAsync { // this looks more familiar :) The fancy async is
// the BoxedAsyncBuilder I mentioned earlier that makes
// it posible to return anything from the route
// (string, object, negotiator)
return "Hello World!"
})
}

```

What we plan to add:

* A bootstrapper builder
* A better looking API from the before and after routes.