bruinbrown / FancyFS

A super simple web framework written in F# for F#
0 stars 0 forks source link

Routing #3

Open bruinbrown opened 10 years ago

bruinbrown commented 10 years ago

Routing will be a pipeline element which should run after authentication etc

bruinbrown commented 10 years ago

Currently considering a few options for routing. Either

  1. Attribute based routing. So every function which maps onto a route should have an attribute:

    [<Route(path="users/hidden" method="GET")>]
    let HiddenUsers input =
     input
  2. A function called CreateRoute which the user calls as follows: CreateRoute reqMethod basePath finalPath pathMatch =
  3. A combination of both. Gives the most choice but it could lead to bad practices across a code base. Some as CreateRoute and some with an attribute
bruinbrown commented 10 years ago

I think option 2 is the better option personally. It could provide a really nice way of handling creating routes within a module. My thoughts on how it should work within a module are as follows.

module UsersModule =
    let CreateUserRoute = CreateRoute "/users"
    let simplePathMatch input =
        AsJson input
    do CreateUserRoute "GET" "/" simplePathMatch

I think that sits as being the best way of organising the parameters

bruinbrown commented 10 years ago

In other related thoughts, currently the router inputs are a request and a response and it then needs to return a request and a response. This strikes me as being too much and there should be a different input and output which would still allow for direct access to the request and the response, then the router maps these onto the actual response. This would be to handle things like parameters passed within the URL.

bruinbrown commented 10 years ago

Routing is currently in a semi functioning state. Further work to be done on it includes

bruinbrown commented 10 years ago

I've been working on the way to create strongly typed access to route parameters lately and progress is good so far. It works through the use of a type provider, but I'm now looking at the best way of initialising it from a given set of routes.
The current options include:

  1. A setup similar to the JSON type provider so you can call RouteProvider<"/test/route/{id}">.Load(receivedPath)
  2. Another constructor which takes in a IDictionary<string, string> and parses through that
  3. Just use the current constructor and have the router parse and convert
    I personally think that 1 is likely to be the best course of action