![]() Traditional route matching tends focus on tables of strings and pattern matching based on the entire URL, but Superscribe is different. Graph based routing is so named because it stores route definitions in – you guessed it – a graph structure. This is kinda cool, but there’s a lot more going on here than meets the eye. The key part to focus on here is the define.Route statement, which allows us to directly assign a handler to a particular route – in this case /hello/world and /hello/fsharp. You can also do all the usual things like specify custom media type serialisers, return status codes etc. Superscribe defaults to a text/html response and will try it’s best to deal with whatever object you return from your handler. Lets have a look at an example application using Superscribe in F#: If you’re building a very content-heavy application then it’s probably not the right choice, but for APIs it’s incredibly performant. This simplicity is a key tenet of graph based routing – keeping things minimal helps us build web applications that respond very quickly indeed as there is simply no extra processing going on. It turns out that routing, content negotiation and some way of invoking a handler is actually all you need to get started building web applications. In fact, that’s somewhat of an oversimplication… in reality this library takes care of everything between URL and handler. What I will say is that Superscribe is not a full blown web framework but actually a routing library. I’m not going to go into detail about it’s features these are language agnostic, and covered by the website and some previous posts. Graph based routing itself has been around for a while, in the form of a library called Superscribe (written in C#). I often find the best way to get acquainted with things is to dive right in, so please feel free to give me pointers in the comments. ![]() So first off – I should point out that I’m not actually an F# guy in fact I’m pretty new to the language in general so this post is also somewhat of a learning exercise for me. This approach is currently known as Graph Based Routing Some background Instead, I’d like to introduce the F# community to a whole new way of thinking about web applications, one that draws inspiration from a number of functional programming concepts – primarily pipelining and function composition – to provide a solid base on to which we can build our web applications in F#. With that in mind, I’m not just going to write another post about how to build web applications with F#. ![]() NET frameworks that weren’t designed specifically for F# and build very solid applications. ![]() Using F# to build web applications is nothing new, we have purpose built F# frameworks like Freya popping up and excellent posts like this one by Mark Seemann. Before we get started I’d just like to mention that this post is part of the truly excellent F# Advent Calendar 2014 which is a fantastic initiative organised by Sergey Tihon, so big thanks to Sergey and the rest of the F# community as well as wishing you all a merry christmas! Introduction ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |