DerekMorrison

On software engineering, .NET, and technology

Queryable Endpoints

It's been several weeks since I went to the Alabama Code Camp that was held here in Huntsville, but there's been one concept that was mentioned in a session that I think has noticeably changed my development habits. It's something I heard mentioned in a talk by Shawn Wildermuth about Microsoft's Astoria project: queryable endpoints.

I think the core idea is that, when structuring a database's schema or when writing data access code, it helps to keep a data model simple and avoid baking inappropriate aspects into it such as aggregate columns or a default sort order. One's goal should instead be to create an understandable, clean model that allows its consumers to transform data themselves (via filtering, sorting, summing columns together, etc).

In the talk, Shawn discussed how the Microsoft data access team is trying to build one solution for this with Astoria. The stated goal of Astoria is "to facilitate the creation of flexible data services that are naturally integrated with the web". In its simplest form, it basically allows you to expose data in a RESTful manner via URLs like this:

http://server/data.svc/Customers

which returns a list of Customer entities, or in a more specific way like:

http://server/data.svc/Customers(’ALFKI’)/Orders?$filter=Active eq true&$orderby=OrderDate

The caller can request that entities be returned in JSON or ATOM format, and the format can be chosen with a flag in the HTTP request header. It seems Astoria provides the mechanism for such communication, but the back end (how you talk with data sources) can be constructed in a variety of ways using .NET (talking to XML files, various databases using ODBC, even remote web services).

While Astoria sounds very exciting, and I hope I get to play with it sometime, just keeping the concept of queryable endpoints conscious has proven beneficial to me on my current project in the past couple weeks. After the code camp talk, I looked back and saw where me and my team had violated this idea in a few particular ways: we had created many inflexible, overly-specific stored procedures in the database such as "GetUsersByLastLoginTimeDesc" and also ones that retrieved records given a filter which ended up being raw SQL (which is certainly not a very maintable practice).

While these may be very glaring examples, sometimes the decisions can be a little more subtle and easier to slip through. This week as I was creating a new data structure as part of the data access layer component of our application, I found myself throwing in an aggregate field which summed together several others. The data structure was to be used in forming a data grid for a specific page and this would have made things easier for that particular page, but I saw where it could easily be useful elsewhere and wanted to of course make it generic. It was a little more work to therefore customize the data grid on my page to create an aggregate column, but looking back I can easily see where that was the proper place to put that piece of logic.

A lot of this is probably common sense or just a feel for software engineering that I haven't quite development yet, but I think keeping this idea in mind has helped me to put code in the right place.

Related Links:
ADO.NET Data Services (Formerly Astoria) Page
ADO Guy
Hanselminutes Podcast 97 - ADO.NET "Astoria" Data Services with Shawn Wildermuth

Comments

April 4. 2008 17:46

Chris Williams

When you blog about what you've learned recently and about the things you're implementing, it reminds me how little I know about programming, databases, and other (what I call) hardcore CS practices. It also re-emphasizes what I already know to be true... the longer it takes WideNet to hire a real programmer and database person, the more code they'll have to fix and/or replace altogether that I'm just skimming by on. Crap I still "left join" every database join I do because I don't have the time and haven't fully grasped the other ways. At least I've started putting more of the code in objects so when the next person comes behind me, then can just fix the objects instead of running around to a bunch of included function calls. Thanks for depressing me. hah.

Chris Williams

April 5. 2008 02:03

Derek

Yes, but I'm just afraid that all the time I spend thinking about programming could have better been spent actually getting things done Smile

Derek

April 5. 2008 06:07

Chris Williams

Well I definitely get a lot done... no doubt about that. I guess that's worth something!

Chris Williams

Add comment


 





Live preview

October 11. 2008 06:26