F# Type Providers and WebAPI

by dotnetnerd 4. April 2012 10:35

imagesLater this month on the 25th I will be speaking along with two other speakers about webframeworks at an ANUG meeting. The frameworks covered are ServiceStack, Nancy and WebAPI where I will cover the latter.

While I have been preparing my eye cought a new feature in F#, which I think is one of the first really good stories for F# that makes sence outside akademia and science. Type Providers give us a way to access data sources that provide its own metadata, and this fits nicely with building WebAPI services.

As an example this snippet of code shows all you have to do to access a database, get intellisence for your types and provide the result as a resource that can be queried using URI Queries - nice and terse!

type dbSchema = SqlDataConnection<"Data Source=MySqlServer;Initial Catalog=peopleDb;Integrated Security=SSPI;">

type PeopleController() =
    inherit ApiController()

    member x.Post(city:string) =
        let db = dbSchema.GetDataContext()
                     
        query {
            for row in db.People do
            where (row.City = city)
            select row
        }

Who am I?

My name is Christian Holm Diget, and I work as an independent consultant, in Denmark, where I write code, give advice on architecture and help with training. On the side I get to do a bit of speaking and help with miscellaneous community events.

Some of my primary focus areas are code quality, programming languages and using new technologies to provide value.

Microsoft Certified Professional Developer

Microsoft Most Valuable Professional

Month List

halk tv