by dotnetnerd
4. April 2012 10:35
Later 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
}