<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
        <title>Document This</title>
        <description>Document This - Michael Pratt</description>
        <link>http://urthen.github.com</link>
        <link>http://urthen.github.com</link>
        <lastBuildDate>2013-06-23T16:07:40-07:00</lastBuildDate>
        <pubDate>2013-06-23T16:07:40-07:00</pubDate>
        <ttl>1800</ttl>


        <item>
                <title>Reasons to use a light on dark color scheme</title>
                <description>&lt;h1 id='its_not_just_to_be_cool'&gt;It&amp;#8217;s not just to be cool.&lt;/h1&gt;

&lt;p&gt;You&amp;#8217;ll often see developers working with a light-on dark color scheme for their web sites, editors, and other applications. I obviously have a dark scheme on this site, and all my primary desktop editors use a dark color scheme. I use a dark terminal, a dark desktop background, and dark themes on every application that supports theming. You might think this is only due to contemporary media branding dark themes &amp;#8220;cool&amp;#8221; or &amp;#8220;retro,&amp;#8221; but there&amp;#8217;s actually some marginally good reasons for it.&lt;/p&gt;

&lt;h2 id='you_might_save_power'&gt;You might save power.&lt;/h2&gt;

&lt;p&gt;It might seem silly, but having a darker theme can actually save you a small but measurable amount of power. &lt;a href='http://www.blackle.com/'&gt;Blackle&lt;/a&gt; claims to save watts by rebranding the Google search homepage with a dark scheme. Google &lt;a href='http://googleblog.blogspot.com/2007/08/is-black-new-green.html'&gt;refuted this&lt;/a&gt; in 2007, claiming that black schemes might actually increase power usage because in many monitors, the white is always on and the black requires energy to block the light. PCStats set out to &lt;a href='http://www.pcstats.com/articleview.cfm?articleID=2649'&gt;test the claims&lt;/a&gt; in 2012. In their testing, a dark color scheme saved 4 watts on their reference LCD monitor. CRT monitors had an even more drastic difference, though at this point they are all but completely obsolete. As of this writing, Blackle claims to have saved over 3.5 million watt-hours of energy by users visiting their site instead of Google&amp;#8217;s home page; though exactly how they measure this, I&amp;#8217;m unsure.&lt;/p&gt;

&lt;p&gt;However, not all monitors are LCD, so I&amp;#8217;m sure this is up for a lot of debate. In an LED monitor (or, more drastically, something like a Jumbotron), where the light actually turns off in black pixels, the power difference between a full black and white screen is probably even more prominent.&lt;/p&gt;

&lt;h2 id='you_might_sleep_better'&gt;You might sleep better.&lt;/h2&gt;

&lt;p&gt;Our sleep is affected in part by a hormone called melatonin. Melatonin promotes sleep and, in effect, tells the body &amp;#8220;It&amp;#8217;s night now, do night things.&amp;#8221; Light hitting the retina surpresses the production of melatonin, and can &lt;a href='http://www.nytimes.com/2011/07/05/health/05light.html?_r=3&amp;amp;pagewanted=all&amp;amp;'&gt;affect your sleep schedule&lt;/a&gt;. According to one study, blue light especially kept subjects awake and alert for up to an hour after exposure. By having a darker scheme, you get less blue light and can get to sleep more normally. There are of course other ways to achieve this - for example, a light red background - but in the abscence of other choices, a black or grey background will affect your sleep far less than a bright white one.&lt;/p&gt;

&lt;h2 id='it_is_easier_to_scan'&gt;It is easier to scan.&lt;/h2&gt;

&lt;p&gt;This part mostly applies to code or terminal windows, but &lt;a href='http://uxmovement.com/content/when-to-use-white-text-on-a-dark-background/'&gt;according to some&lt;/a&gt;, light text on a darker background is easier to quickly read in short scans. This is because white light, being made of every color combined, stimulates every color receptor in the eye. The extra light stands out in contrast to the background and is easy to scan across. The lighter the text, the more pronounced the effect - notice how easy it is to quickly scan the title of this post. However, brighter text also tends to become blurred and strain the eyes due to scattering, which makes reading a full paragraph of bright white text on a full black background very stressful on the eyes. To mitigate this, light grey/dark grey schemes like this one are generally used for longer text such as this paragraph.&lt;/p&gt;

&lt;h2 id='older_readers_may_have_an_easier_time_with_it'&gt;Older readers may have an easier time with it&lt;/h2&gt;

&lt;p&gt;According to the &lt;a href='http://www.afb.org/section.aspx?TopicID=200&amp;amp;DocumentID=210'&gt;American Federation for the Blind&lt;/a&gt;, &amp;#8220;Contrast is one of the most critical factors in enhancing visual functioning.&amp;#8221; They suggest that text always be printed with the best possible contrast to allow sight impaired users to consume it more easily. They mention that for many older people a light-on-dark scheme is easier to read than black on white. This is the origin of both the &amp;#8220;high contrast&amp;#8221; and &amp;#8220;inverted colors&amp;#8221; schemes available in many operating systems. This generally isn&amp;#8217;t a concern for most code editors or tech sites, but if you&amp;#8217;re aiming for an older audience, you may want to consider adding these options.&lt;/p&gt;

&lt;p&gt;Of course, there&amp;#8217;s data that goes the other way on this, as well. People with astigmatism &lt;a href='http://blog.tatham.oddie.com.au/2008/10/13/why-light-text-on-dark-background-is-a-bad-idea/'&gt;may have a harder time&lt;/a&gt; reading light on dark text. Because the iris must open wider to take in the decreased light, their lens deformation is exaggerated and contributes to fuzzy looking text.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m not suggesting every web site run out and switch to a light on dark theme, obviously. But next time you see someone with a dark color scheme, it might not &lt;em&gt;just&lt;/em&gt; be because it&amp;#8217;s freaking cool.&lt;/p&gt;</description>
                <link>http://urthen.github.com/2013/06/23/reasons-to-use-a-light-on-dark-color-scheme</link>
                <guid>http://urthen.github.com/2013/06/23/reasons-to-use-a-light-on-dark-color-scheme</guid>
                <pubDate>2013-06-23T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>Ways to version your API, Part 2</title>
                <description>&lt;h1 id='part_two_how_to_architect_a_versionless_api'&gt;Part two: How to architect a version-less API&lt;/h1&gt;

&lt;p&gt;This is part two of a series on API versioning. &lt;a href='/2013/05/09/ways-to-version-your-api/'&gt;Part One&lt;/a&gt; covered the prevailing methods for versioning your API and allowing clients to code against one version specificically. I suggest you read that post (at least skim the intro!) before this one as it provides some neccesary context. In it, I hinted to another method utilizing some little-known concepts of the Accepts header spec might allow you to make a version-less API. I&amp;#8217;ll admit right up front, however, it&amp;#8217;s a bit of a misnomer, but I think it&amp;#8217;s still important. You can still version things in the API, but you aren&amp;#8217;t versioning the interface itself. You&amp;#8217;re merely versioning the resource representations.&lt;/p&gt;

&lt;p&gt;The most common change in any REST architected API is adding, changing, or removing fields from the resources. New information is added or may be in a different format. Information may become unavailable. You may also add, move, or remove resources themselves. Depending on your API architecture, the HTTP verbs may mean slightly different things. All of these typically would require an API version increment if they would cause existing applications to break. With a little forethought, however, your API can change without requiring a whole API versioning strategy.&lt;/p&gt;

&lt;p&gt;Architect a versionless interface:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use sane URI schemes: &lt;code&gt;/api/collection_name/resource_id&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;Follow definitions of HTTP methods&lt;/li&gt;

&lt;li&gt;Adding resources should always be backwards compatible&lt;/li&gt;

&lt;li&gt;Removing resources would have to be done across versions anyway&lt;/li&gt;

&lt;li&gt;Moving resources can be handled by redirect HTTP codes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Version resource representations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use the Accepts header&lt;/li&gt;

&lt;li&gt;Adding information should always be backwards compatible&lt;/li&gt;

&lt;li&gt;Removing information would have to be done across versions anyway&lt;/li&gt;

&lt;li&gt;Moving information can be done with Accepts versioning&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='architecting_a_versionless_api'&gt;Architecting a version-less API&lt;/h2&gt;

&lt;p&gt;Let me begin by saying that I acknowledge that a version-less API is a bit of an ideal state, and an API with a well-thought versioning strategy is far preferable to an API with a poorly thought out attempt to not version. There&amp;#8217;s no shame in saying that you think you need versioning, nor can every possible API fit into this versionless strategy. It really only works for REST-architected, resource manipulation based APIs that follow prevailing standards. That said, a great deal of APIs can be reworked to fit into this style. Additionally, this is intended for backend APIs, not APIs interfacing with your web front-end. In my opinion, these should almost always be separate APIs so that you can update the web front end functionality at your own pace without worrying about any users of the API. I know I personally am a lot more lax in my following of standards for front-end APIs.&lt;/p&gt;

&lt;p&gt;The first step of understanding how to create a versionless API is knowing that you don&amp;#8217;t want to version the interface itself. That means, you don&amp;#8217;t want to change how and where information is stored and accessed. In practical terms, this is the URI structure. Even this rule can be bent, of course - built right into the HTTP spec are redirects! If you&amp;#8217;ve moved information, simply provide a permanent redirect to the new URI. Now, what happens if you remove a resource?&lt;/p&gt;

&lt;p&gt;There&amp;#8217;s two reasons a particular URI might be removed from a typical API: Either the resource type itself has been removed, or more commonly, that particular representation of the resource is no longer supported. In the latter case, you&amp;#8217;re not really adhering to REST architecture: The resource representation should be decoupled from the URI. In the former case, if the entire resource type no longer is accessible, it&amp;#8217;s probably for a business reason, in which case you&amp;#8217;d want to remove it from all previous versions of the API as well. In that case, versioning didn&amp;#8217;t really get you anything, did it?&lt;/p&gt;

&lt;p&gt;Adding resources, or information to resources, should always be a backwards-compatible change. If you&amp;#8217;re using JSON, adding elements to existing resources should be a breeze. Even if you have an XML schema, you can simply add them to the defined schema and alert clients who may have downloaded their own copy of the schema to update it. If you&amp;#8217;d like to add an entirely new resource, simply add it! Nobody should be affected.&lt;/p&gt;

&lt;p&gt;Probably the most difficult thing to make versionless is any changes to what happens when you perform a particular method on a particular API. For example, if you used to be able to POST to &lt;code&gt;/api/foo/&lt;/code&gt; and have it create a new &lt;code&gt;foo&lt;/code&gt; resource for you, but now you want it to edit an existing &lt;code&gt;foo&lt;/code&gt; resource. The best I can tell you is dont, instead follow the &lt;a href='http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html'&gt;recommended HTTP spec method definitions&lt;/a&gt; explicitly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;GET /api/foo/&lt;/code&gt; or &lt;code&gt;GET /api/foo/1&lt;/code&gt; retrieves resources or resource collections and is idempotent (repeatable with the same results)&lt;/li&gt;

&lt;li&gt;&lt;code&gt;POST /api/foo/&lt;/code&gt; creates new resources and is NOT idempotent (repeating creates more resources)&lt;/li&gt;

&lt;li&gt;&lt;code&gt;PUT /api/foo/1&lt;/code&gt; updates or creates an entire specific resource and is idempotent&lt;/li&gt;

&lt;li&gt;&lt;code&gt;PATCH /api/foo/1&lt;/code&gt; (&lt;a href='http://tools.ietf.org/html/rfc5789'&gt;proposed standard&lt;/a&gt;) updates fields of a specific resource and is idempotent&lt;/li&gt;

&lt;li&gt;&lt;code&gt;DELETE /api/foo/1&lt;/code&gt; deletes a resource (sometimes resource collections) and is idempotent&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Technically, I think DELETE should notify somehow if the resource didn&amp;#8217;t exist in the first place and a proper way to do that would be an error, but I&amp;#8217;ll defer on that one. OPTIONS and HEAD are used less and if you&amp;#8217;re using them, you probably know what you&amp;#8217;re doing anyway. If you&amp;#8217;re using PATCH, be aware it isn&amp;#8217;t a well supported standard, and many APIs will accept incomplete PUT requests and only update changed fields. I think this is fine so long as it&amp;#8217;s a well understdood and documented behavior given spotty PATCH support, at least until it&amp;#8217;s more widely acceptable.&lt;/p&gt;

&lt;p&gt;A lot of times, resources are modified by POST requests. A form submits, you interpret the data and change a resource. This is a common pattern in front-end APIs, and as I mentioned above, that&amp;#8217;s fine. Not perfect, but fine. In a back-end API, this shouldn&amp;#8217;t happen! Use a PUT or PATCH request and explicitly define what you want the new resource to be. A common excuse is old versions of IE don&amp;#8217;t support PUT or PATCH, but this is a back-end API, it&amp;#8217;s fine! Every major library I know of at least supports PUT - if you&amp;#8217;re using one that doesn&amp;#8217;t, you should probably look elsewhere.&lt;/p&gt;

&lt;p&gt;In short, a prerequisite to versionlessness is that every resource you have should be able to be accessed and manipulated in a consistent fasion, with the only directives being the URI to the resource, HTTP method, and the data representing the resource itself. If you&amp;#8217;re manipulating a single logical resource - say, a user profile - from multiple URIs, you&amp;#8217;re likely going to encounter situations where you need to version.&lt;/p&gt;

&lt;h2 id='versioning_resource_representations'&gt;Versioning resource representations&lt;/h2&gt;

&lt;p&gt;As I mentioned in the intro, the resource representations themselves transferred to the client can and probably should be versioned. The beauty of this approach is that each resource can be versioned independently. If you change one resource, then a month later decide to change a different resource, you don&amp;#8217;t have to increment an API version counter twice. Each resource version is incremented individually. Note that I&amp;#8217;m not talking about versioning the resources themselves, just the representation of the resource. If you have a versioned resource, for example a document that has previous revisions available, these should be accessed separately than the method I&amp;#8217;m describing here.&lt;/p&gt;

&lt;p&gt;Familiarizing yourself with the &lt;a href='http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html'&gt;Accept header spec&lt;/a&gt; will probably help you understand the true depth of how far specs can go towards future-proofing themselves. Almost everyone knows the Accepts header specifies what kind of MIME-Type the requestor expects, like &lt;code&gt;application/json&lt;/code&gt;. Fewer know that it can not only specify one type, but it can specify multiple acceptable types as well as parameters on each type. In order to version resource representations, we&amp;#8217;re going to take advantage of the type parameters.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ll jump in and have you consider the following:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;application/vnd.example.foo+json;version=2,application/vnd.example.foo+json&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Even without fully understanding the Accepts header, you can probably guess this string implies that it expects the &lt;code&gt;application/vnd.example.foo&lt;/code&gt; type in &lt;code&gt;json&lt;/code&gt; format, version 2 if available, and any version otherwise. Parsing the Accepts header in a manner consistent with the spec can be difficult only because many libraries do not parse it out of the box.&lt;/p&gt;

&lt;p&gt;So, when should you version resource representations? As I mentioned above, if you&amp;#8217;re removing information about a resource, it&amp;#8217;s probably for a business reason that you don&amp;#8217;t want it exposed anymore. In today&amp;#8217;s age of compressed transmission, there&amp;#8217;s little gain to be had from removing information simply because you don&amp;#8217;t feel it is useful anymore. Adding information should always be possible to be done in a backwards-compatible manner. You might want to version in cases of changing the name and/or type of a field, for example if you want to (real world example time!) repurpose a boolean field labeled &amp;#8220;enabled&amp;#8221; to a more generic &amp;#8220;status&amp;#8221; enum type.&lt;/p&gt;

&lt;h2 id='now_how_do_i_do_this'&gt;Now, how do I do this?&lt;/h2&gt;

&lt;p&gt;Unfortunately, much of what I&amp;#8217;ve discussed here has little to no broad support in the community of people actually building widely used APIs. I suspect no small part of this is due to the difficulty implementing these in a real world application. Depending on your platform it may be easy or difficult, and few libraries will support a versioning strategy like this out of the box. The closest I know if is &lt;a href='http://mcavage.github.io/node-restify/#Routing'&gt;node-restify&lt;/a&gt; which supports versioned routing based on an &lt;code&gt;Accepts-version&lt;/code&gt; header.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m going to be going through some libraries and attempting to extend them to support versioning in the future. Possibly attempting my own library that bakes a lot of this in for free. The easier it is for a developer to write standards-compliant code, the more likely they will adopt it, because in the end if it comes down to ease of development vs adherence to standards, I think we all know ease will win out every time.&lt;/p&gt;</description>
                <link>http://urthen.github.com/2013/05/16/ways-to-version-your-api-part-2</link>
                <guid>http://urthen.github.com/2013/05/16/ways-to-version-your-api-part-2</guid>
                <pubDate>2013-05-16T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>Ways to version your API</title>
                <description>&lt;h1 id='part_one_pros_and_cons_of_various_methods_to_version_your_api'&gt;Part one: Pros and cons of various methods to version your API&lt;/h1&gt;

&lt;p&gt;Anyone designing an HTTP API with versioning in mind for the first time might be surprised to learn there is no universally accepted method, nor any standard explaining how. This post will be part one of a two part series on API versioning. In this post, I&amp;#8217;ll cover some API versioning methods used today and the pros and cons of each. In &lt;a href='/2013/05/16/ways-to-version-your-api-part-2/'&gt;part two&lt;/a&gt;, I&amp;#8217;ll be describing some strategies you can keep in mind when designing your API to obviate the need to version at all.&lt;/p&gt;

&lt;p&gt;There’s a lot of ways to version your API, and if you’ve ever had to change your API drastically, you’ve probably been glad you had a versioning methodology in place. If you didn’t, you probably WISH you did. However, anyone designing such a methodology for the first time might be surprised to know there is no universally accepted method for versioning your API, nor does any standard specify one.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s what I have found to be the most common methods of API versioning, in order of least to most desirable in my opinion:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Changing hostnames&lt;/li&gt;

&lt;li&gt;Adding /v1/ to the URI&lt;/li&gt;

&lt;li&gt;Adding ?version=1 to the query parameters&lt;/li&gt;

&lt;li&gt;Passing a custom header&lt;/li&gt;

&lt;li&gt;Specifying a parameter in the accepts header&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Before I can do that, I must explain what the standards say and explain my interpretation of what the web was envisioned to be.&lt;/p&gt;

&lt;p&gt;A URI - Uniform Resource Identifier - is defined in &lt;a href='http://tools.ietf.org/html/rfc3986'&gt;RFC 3986&lt;/a&gt; as a compact sequence of characters that identifies an abstract or physical resource. URIs are, for practical purposes, a superset of URLs (Uniform Resource Locators) and the terms are often used interchangably, if incorrectly. Any API which operates over HTTP at one point has to deal with what URIs point to what resource; whether that is one global resource which all operations flow through or a subnet of resources in a logical arrangement. However, it is important to note that the URI does not specify whatsoever the representation of the resource. This will be important later.&lt;/p&gt;

&lt;p&gt;The specification itself does not indicate a URI always has to point to the same resource, though you tend to break client applications if you move resources without warning. As such, if you change your URI scheme, you should either leave the existing URI scheme in place, or leave breadcrumbs to find the new resources. Leaving breadcrumbs will be covered in the next post, so let&amp;#8217;s talk about how to change your API while letting people still use it the old way. Keep in mind that these are all general opinions: Sometimes your specific API needs will make one choice drastically better than another that I said was better, so always use your own judgement!&lt;/p&gt;

&lt;h2 id='changing_hostnames'&gt;Changing Hostnames&lt;/h2&gt;

&lt;p&gt;I&amp;#8217;m going to barely touch upon this method, since it&amp;#8217;s barely used, and even then only in the most extensive of API revamps. Essentially, you&amp;#8217;re moving the API from one hostname to another. You might even just call this building a new API to the same resources. Downsides of this method are above and beyond all others - in addition to changing what URIs are being used, clients may have to change their security settings to access the new hostname. The only upside is that you can completely revamp the enture URI structure - including adding a version parameter if you didn&amp;#8217;t have one before. You can also easily route it to a completely different server, so the old one can continue serving just the old API. But then you&amp;#8217;ve got two servers - Expensive!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Short story:&lt;/strong&gt; Don&amp;#8217;t consider this unless you &lt;em&gt;really&lt;/em&gt; messed up the first time and want to completely start over.&lt;/p&gt;

&lt;h2 id='adding_version_to_the_uri_path'&gt;Adding version to the URI path&lt;/h2&gt;

&lt;p&gt;This is by far the most common method currently in use by APIs today. It&amp;#8217;s fairly straightforward from an initial implementation standpoint. Simply add a /v1/ or similar to the URI, like this: &lt;code&gt;http://example.com/api/v1/foo/bar&lt;/code&gt;. Alternately, you can avoid putting v1 in the URI initially, and if you have to version, change the URI to &lt;code&gt;http://example.com/api_v2/foo/bar&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It&amp;#8217;s very easy to code into the first API, and it&amp;#8217;s very easy for users to understand what that number means. You can change the entire path after the version number between revisions and not break existing clients. Depending on what server technology you are using, it may be easy or hard to increment the version. If you need to copy and paste code to make this method work, you might want to stay away - it makes the separation very easy, but maintenance can be difficult. Imagine if you had to fix a bug for all versions of the API, and you&amp;#8217;re already on version ten! Find-and-replace nightmare.&lt;/p&gt;

&lt;p&gt;Deprecating a version - if you do it nicely - can be straightforward, and even easy in some technologies. Redirect all requests to the old, deprecated version resources to a newer version. You&amp;#8217;ll still want to notify users ahead of time, but this way their clients might not break when you deprecate a version. Since nobody can &lt;em&gt;not&lt;/em&gt; use a version, you&amp;#8217;ll potentially break everyone if you don&amp;#8217;t give them enough time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Short story:&lt;/strong&gt; If you read this entire article (and the followup) and still have no idea what you&amp;#8217;re doing, just stick /v1/ in the URI somewhere and figure it out later. This method works for everyone else in the end, you can probably get it to work too - even if you may regret it later.&lt;/p&gt;

&lt;h2 id='version_in_the_query_parameters'&gt;Version in the query parameters&lt;/h2&gt;

&lt;p&gt;This one is, in my experience, the second most common versioning method. Again, it is straightforward from an initial implementation standpoint: Add version query parameter, even if it is completely ignored. URIs might look like this: &lt;code&gt;http://example.com/api/foo/bar/?version=1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;One advantage of this option is it can be optional or required depending on how you want the API to be used. Some APIs require every request to include the version, others assume the latest version if the request left it off. Like adding it to the URI path, this is very easy to see, understand, and initial code implementation is trivial. In fact, you can probably just ignore it until you actually have a v2!&lt;/p&gt;

&lt;p&gt;However, you can&amp;#8217;t as easily change the path, so moving resources can be painful. Additionally, you&amp;#8217;re often forced to put in place transform layers to change the data representation between versions if the representation has changed. You generally don&amp;#8217;t redirect solely on a query parameter being wrong, so redirecting existing users on a deprecated version to a supported version generally can&amp;#8217;t be done. However, you can do this transparently by silently serving up the newer version if you think that&amp;#8217;s more appropriate than simply breaking.&lt;/p&gt;

&lt;p&gt;If you have an API that actually versions resources themselves through query parameters, you&amp;#8217;ll probably want to stay away from specifying API version in the query parameters as well. That could get confusing! Use either of the methods below instead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Short story:&lt;/strong&gt; An acceptable method when you only want to version the resource representations. Versioning paths will be harder, so keep that in mind. Few benefits over adding it to the URI path.&lt;/p&gt;

&lt;h2 id='passing_a_custom_header'&gt;Passing a custom header&lt;/h2&gt;

&lt;p&gt;This method is similar to the previous; instead of specifying it in the query parameters you specify it in the headers. For example, to use cURL to get from an API like this, you would specify &lt;code&gt;curl -H &amp;quot;Accepts-version: 1.0&amp;quot; http://www.example.com/api/foo/bar&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Largest advantage of this scheme is mostly semantics: You aren&amp;#8217;t cluttering the URI with anything to do with the versioning. The URI should be specifying what the resource is, not how you want it represented. However, you also are making up headers. While from a technology standpoint it will work, it loses some purism points.&lt;/p&gt;

&lt;p&gt;Other benefits include easily being able to ignore it or silently upgrade if the user does not specify, or specifies a deprecated version. Downsides are similar to version in the query parameters. Additionally, depending on what tools you have it can be difficult to specify. Hint: Get &lt;a href='https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm?hl=en'&gt;Postman for Chrome&lt;/a&gt;, it makes specifying headers easy!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Short story:&lt;/strong&gt; A neater way to version than with query parameters, and avoids some complications. However, it can be difficult from a usability standpoint.&lt;/p&gt;

&lt;h2 id='specifying_a_parameter_in_the_accept_header'&gt;Specifying a parameter in the Accept header&lt;/h2&gt;

&lt;p&gt;For now, I&amp;#8217;ll simply mention that the &lt;a href='http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html'&gt;Accept header spec&lt;/a&gt; allows for custom vendor media types, and for parameters to be passed as part of the content negotiation. This is a perfectly valid Accepts header: &amp;#8220;application/vnd.urthen.example?version=1.0&amp;#8221;&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ll be going over this method in much more detail in &lt;a href='/2013/05/16/ways-to-version-your-api-part-2/'&gt;part two of API Versioning&lt;/a&gt;. To understand why this method is ideal in my opinion, you&amp;#8217;ll also need to understand my thoughts on how to create an unversioned API. Make sure to follow me on twitter to know when it is posted.&lt;/p&gt;</description>
                <link>http://urthen.github.com/2013/05/09/ways-to-version-your-api</link>
                <guid>http://urthen.github.com/2013/05/09/ways-to-version-your-api</guid>
                <pubDate>2013-05-09T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>Pros and cons of Amazon SimpleDB</title>
                <description>&lt;h1 id='or_why_the_easiest_solution_isnt_always_the_best'&gt;Or, why the easiest solution isn&amp;#8217;t always the best&lt;/h1&gt;

&lt;p&gt;Amazon&amp;#8217;s &lt;a href='http://aws.amazon.com/simpledb/'&gt;SimpleDB&lt;/a&gt; service is a very easy to set up and maintain non-relational data store, hosted in their cloud infrastructure. I used it during the creation of a new project as I wanted something simple and easy to implement. SimpleDB was just that. However, it has quite a few limitations. Without getting into too much detail, make sure you take the following into account before you start coding:&lt;/p&gt;

&lt;h2 id='the_good'&gt;The Good&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Easy to set up - No special configuration required, just one command to initialize the store.&lt;/li&gt;

&lt;li&gt;No Maintenance - Assuming Amazon doesn&amp;#8217;t go under, your data is relatively safe&lt;/li&gt;

&lt;li&gt;Low cost - Nearly free for small data sets and throughput&lt;/li&gt;

&lt;li&gt;Query syntax based on SQL&lt;/li&gt;

&lt;li&gt;Exposed in the Python &lt;a href='https://github.com/boto/boto'&gt;Boto&lt;/a&gt; package for Amazon services&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='the_bad'&gt;The Bad&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Slow to write - Can only write a maximum of 25 entries at a time&lt;/li&gt;

&lt;li&gt;Slow to read - Can only read ~1kb of data per request&lt;/li&gt;

&lt;li&gt;Flat structure - If you input nested JSON objects, you need to parse the deep objects out of packed strings&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='conclusions'&gt;Conclusions?&lt;/h2&gt;

&lt;p&gt;In short, it&amp;#8217;s a fine service - if you use it correctly. I was trying to use it as a caching service, however. At only 5000 entries, it takes several seconds to read the entire data set, even with no further calculations, just retrieving the data. This was after minimizing the data returned so that I could read the maximum amount before reaching the 1kb limit. I think I&amp;#8217;ll soon be switching to something more appropriate. I know Redis will be up to the task, I just need to figure out how to host it properly.&lt;/p&gt;

&lt;p&gt;If you&amp;#8217;re writing data fairly slowly, and don&amp;#8217;t need to read the entire data set rapidly either, it might suit your purposes. This isn&amp;#8217;t a condemnation of SimpleDB by any means, just don&amp;#8217;t try and make it do things it wasn&amp;#8217;t meant to!&lt;/p&gt;</description>
                <link>http://urthen.github.com/2013/04/29/pros-and-cons-of-amazon-simpledb</link>
                <guid>http://urthen.github.com/2013/04/29/pros-and-cons-of-amazon-simpledb</guid>
                <pubDate>2013-04-29T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>Explorations in Python and TeamCity</title>
                <description>&lt;h1 id='experiments_performing_continuous_integration_testing_in_python_with_teamcity'&gt;Experiments performing continuous integration testing in Python with TeamCity&lt;/h1&gt;

&lt;p&gt;At &lt;a href='http://www.bazaarvoice.com'&gt;Bazaarvoice&lt;/a&gt;, we use &lt;a href='http://www.jetbrains.com/teamcity/'&gt;TeamCity&lt;/a&gt; for continuous integration testing. This has proved immensely useful for most of our Java projects, however as I am developing a Python application, I wanted to see if I could get TeamCity to run testing on my program. I already had a set of unit tests with pretty good code coverage, running fairly fast on my dev machine, so this was mainly an exercise to keep myself honest and track mistakes. No longer could I conveniently &amp;#8220;forget&amp;#8221; to run the tests before deploying, I want publicly fail within moments of pushing buggy code to master!&lt;/p&gt;

&lt;p&gt;While proper unit testing is a topic covered elsewhere in far more detail and with far more expertise than I can provide, I want to share one tidbit that I have found to be the most important moment of &amp;#8220;oh, now I get it&amp;#8230;&amp;#8221; as I&amp;#8217;ve been learning how to properly design unit testing. Anytime something breaks, whether it&amp;#8217;s in production, QA, or on your dev machine, immediately make sure there&amp;#8217;s a corresponding unit test that breaks as well. If there isn&amp;#8217;t, write one before fixing the bug. That way you&amp;#8217;re sure it won&amp;#8217;t happen again. I won&amp;#8217;t overly evangelize unit testing, as I&amp;#8217;ve been on teams who use it as a crutch, but with this one rule you can save yourself hours fixing bugs you&amp;#8217;ve already fixed.&lt;/p&gt;

&lt;p&gt;Anyway, as it turns out, JetBrains has already released a module called &lt;a href='https://github.com/JetBrains/teamcity-python'&gt;teamcity-messages&lt;/a&gt;, available via &lt;code&gt;easy_install&lt;/code&gt; or &lt;code&gt;pip&lt;/code&gt;. This module provides hooks for the &lt;code&gt;unittest&lt;/code&gt;, &lt;code&gt;nose&lt;/code&gt;, and &lt;code&gt;py.test&lt;/code&gt; unit testing frameworks in Python. I&amp;#8217;m simply using &lt;code&gt;unittest&lt;/code&gt;, though I imagine working with the other two is similarly easy. The module is designed to be able to detect whether or not the test is being run from TeamCity, and if so, format the output in a way that TeamCity can immediately report and track tests as they run. When I started my project and unit tests took five seconds to run, there wasn&amp;#8217;t much point, but now that unit testing takes a minute or so it can be helpful. For some of our larger projects which take an hour or more to run the full test suite, it&amp;#8217;s critical to see failures immediately.&lt;/p&gt;

&lt;h2 id='adding_teamcitymessages_to_your_tests'&gt;Adding teamcity-messages to your tests&lt;/h2&gt;

&lt;p&gt;Using &lt;code&gt;unittest&lt;/code&gt; with tests split into multiple modules can be fairly boilerplate - have one testing script that uses &lt;code&gt;unittest.defaultTestLoader&lt;/code&gt;, then use &lt;code&gt;unittest.TextTestRunner&lt;/code&gt; to run the loaded suite of tests. &lt;code&gt;teamcity-messages&lt;/code&gt; plays perfectly into that, as all you need to adjust is what runner you use. Here&amp;#8217;s my current code:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;from teamcity import is_running_under_teamcity
from teamcity.unittestpy import TeamcityTestRunner
import unittest
from tests import testApp, testService, (etc...)

if __name__ == &amp;#39;__main__&amp;#39;:
    if is_running_under_teamcity():
        runner = TeamcityTestRunner()
    else:
        runner = unittest.TextTestRunner()

    suite = unittest.defaultTestLoader.loadTestsFromModule(testApp)
    suite.addTests(unittest.defaultTestLoader.loadTestsFromModule(testService))
    (etc...)
    runner.run(suite)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The only change from when I originally wrote the test file was checking to see if we were running under TeamCity, and loading the appropriate test runner. Now, the testing script will run all my tests on both my development machine and TeamCity. No adjustments were needed to any of the tests themselves.&lt;/p&gt;

&lt;h2 id='getting_your_agents_running'&gt;Getting your agents running&lt;/h2&gt;

&lt;p&gt;Now that we&amp;#8217;ve got our tests reporting to TeamCity when they are actually run there, lets get them running there. Turns out, this was actually the harder part of the operation. The first step was setting up the VCS root to read from the project on GitHub. This was simple to do from the build configuration settings, and we were able to leave most options at default. Then, in the &amp;#8216;Build Triggering&amp;#8217; section, set up a trigger to build after every VCS change. That is, anytime a change to the branch TeamCity is listening to (default is master, but can be changed), it&amp;#8217;ll perform the build steps. This means you should probably have developers pushing code directly to their own branches, and only push to master when it&amp;#8217;s ready for public consumption - even if that doesn&amp;#8217;t mean a release.&lt;/p&gt;

&lt;p&gt;The build steps, too, were fairly simple. In addition to my Python &lt;code&gt;unittest&lt;/code&gt; script, I also use &lt;a href='http://gruntjs.com/'&gt;Grunt&lt;/a&gt; to lint my code. Adding these was as simple as adding two Command Line build runners: &lt;code&gt;python26 testing.py&lt;/code&gt; for the Python tests, and &lt;code&gt;node_modules/grunt/bin/grunt&lt;/code&gt; to run Grunt. Python26 was selected due to version conflicts on the build agents. I ran Grunt that way so it didn&amp;#8217;t have to actually be installed, it could be in the source code.&lt;/p&gt;

&lt;p&gt;However, this was pretty much the end of the simple tasks. Turns out, it isn&amp;#8217;t perfectly straightforward to install python requirements onto a build agent. For our purposes we ended up installing the requirements on all the agents manually, however to keep this working in the future we&amp;#8217;d have to add this step to the build agent deployment script. Additionally, once I added some dependencies to AWS services, transferring the IAM credentials to the testing boxes proved to be a challenge we never ended up surmounting before my DevOps engineer working on the project shifted off, and I needed to continue myself.&lt;/p&gt;

&lt;h2 id='in_conclusion'&gt;In Conclusion&lt;/h2&gt;

&lt;p&gt;Unfortunately, I&amp;#8217;m somewhat sad to say (given how much work went into it) that my TeamCity build configuration is paused with the solemn message &amp;#8220;Discontinued until I figure out how to make it run without errors.&amp;#8221; I still run the same exact tests locally, and as I am the only engineer on the project I have no pressing need to ensure all code is tested as it is checked in. In the future, there&amp;#8217;s a couple things I&amp;#8217;d like to do to fix things, however.&lt;/p&gt;

&lt;p&gt;I believe I can install the Python modules to the agents as local modules, rather than global installations. I always use &lt;a href='http://www.virtualenv.org/en/latest/'&gt;virtualenv&lt;/a&gt;, so my &lt;code&gt;requirements.txt&lt;/code&gt; stays up to date. Since the build runners don&amp;#8217;t have root permissions, I can&amp;#8217;t install packages globally. Neither can I easily set up virtual environments on the build agents. I believe I can install them to the source directory with some variation of &lt;code&gt;pip install --install-option=&amp;quot;--prefix=$PREFIX_PATH&amp;quot; package_name&lt;/code&gt; but I haven&amp;#8217;t gotten into testing this.&lt;/p&gt;

&lt;p&gt;As for the AWS credentials, I&amp;#8217;m not sure how I&amp;#8217;ll get them into the build agents. I&amp;#8217;m sure other teams have done something so once I get the packages installing correctly, I will ask around. Another alternate is simply mock out all AWS services. For some functions like sending email this makes the most sense anyway.&lt;/p&gt;

&lt;p&gt;Hopefully soon, I&amp;#8217;ll be back up and running with TeamCity and will make a new post about the changes. Until then, I&amp;#8217;ll dutifully maintain my unit testing locally in the hopes it may become automated again in the future.&lt;/p&gt;</description>
                <link>http://urthen.github.com/2013/04/24/explorations-in-python-and-teamcity</link>
                <guid>http://urthen.github.com/2013/04/24/explorations-in-python-and-teamcity</guid>
                <pubDate>2013-04-24T00:00:00-07:00</pubDate>
        </item>

        <item>
                <title>Deploying a blog to Github in 30 minutes or less</title>
                <description>&lt;h1 id='an_introduction_to_installing_and_setting_up_jekyll'&gt;An introduction to installing and setting up Jekyll&lt;/h1&gt;

&lt;p&gt;There&amp;#8217;s a whole lot of ways out there to start a blog. From &lt;a href='http://wordpress.org/'&gt;WordPress&lt;/a&gt; to &lt;a href='http://www.blogger.com/'&gt;Blogger&lt;/a&gt; to &lt;a href='http://www.tumblr.com/'&gt;Tumblr&lt;/a&gt;, you can set up your own soapbox in a matter of moments. Some of us, however, desire a more hands-on approach. Fortunately there&amp;#8217;s a way to have a completely self-managed blog without having to spend a dime on hosting costs.&lt;/p&gt;

&lt;p&gt;Enter &lt;a href='http://pages.github.com/'&gt;Github Pages&lt;/a&gt;. GitHub will let you create and host static HTML pages, or pages written with &lt;a href='https://help.github.com/articles/github-flavored-markdown'&gt;Markdown&lt;/a&gt;. Additionally, it&amp;#8217;ll let you deploy with a templating language called &lt;a href='https://github.com/mojombo/jekyll'&gt;Jekyll&lt;/a&gt;, allowing you to quickly and easily deploy blog-like pages. A final piece of the puzzle: &lt;a href='http://www.jekyllbootstrap.com/'&gt;Jekyll Bootstrap&lt;/a&gt;, a fully-featured themable blog framework that takes most of the work out of setting up a simple blog. There&amp;#8217;s excellent documentation on the Jekyll Bootstrap site detailing the very few steps neccesary to get yourself up and running. I&amp;#8217;ll be going over everything from &amp;#8220;Hm, I should start a blog&amp;#8230;&amp;#8221; to &amp;#8220;Hey, that was easy!&amp;#8221;&lt;/p&gt;

&lt;h2 id='installation'&gt;Installation&lt;/h2&gt;

&lt;p&gt;First, you&amp;#8217;ll want to make sure you&amp;#8217;ve got &lt;a href='http://www.ruby-lang.org/en/'&gt;Ruby&lt;/a&gt; installed. If you&amp;#8217;re running a Mac, it probably already is. Once you&amp;#8217;ve got that, install Jekyll with &lt;code&gt;gem install jekyll&lt;/code&gt;. Now create the &lt;code&gt;your-username.github.com&lt;/code&gt; repository in GitHub&amp;#8230; replace &lt;code&gt;your-username&lt;/code&gt; with your actual GitHub username, of course. That&amp;#8217;s it for prerequisites, and if you&amp;#8217;re on schedule, that should have only taken about ten minutes or so.&lt;/p&gt;

&lt;p&gt;Next ten minutes will be to set up and configure Jekyll Bootstrap. Following the instructions from the Bootstrap site, enter the following commands in your preferred projects directory (I like &lt;code&gt;~/Projects/&lt;/code&gt; myself):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ git clone https://github.com/plusjade/jekyll-bootstrap.git your-username.github.com
$ cd your-username.github.com
$ git remote set-url origin git@github.com:your-username/your-username.github.com.git
$ git push origin master&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You should now be able to go to &lt;code&gt;https://your-username.github.com/&lt;/code&gt; and see the Jekyll Bootstrap demo live, as well as run &lt;code&gt;rake preview&lt;/code&gt; and visit &lt;code&gt;http://localhost:4000/&lt;/code&gt; to see it hosted on your machine.&lt;/p&gt;

&lt;h2 id='configuration'&gt;Configuration&lt;/h2&gt;

&lt;p&gt;If you&amp;#8217;d like to use a theme, now would be a good time to install one. Visit the &lt;a href='http://themes.jekyllbootstrap.com/'&gt;Theme browser&lt;/a&gt; and choose one - you can adjust it later, of course, but it&amp;#8217;s just a starting point. Click &amp;#8220;Install Theme&amp;#8221; at the bottom left to be given a commandline to install the theme to your project. You should be given the choice to switch to that theme immediately; you can switch later with &lt;code&gt;rake theme:switch theme-name&lt;/code&gt; if you wish.&lt;/p&gt;

&lt;p&gt;Now let&amp;#8217;s do some configuration. &lt;code&gt;index.md&lt;/code&gt; describes a few, but you&amp;#8217;ll really want to investigate &lt;code&gt;_config.yml&lt;/code&gt; for the full list. At the least, you&amp;#8217;ll want to check out the following:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;title
tagline
author
production_url
JB
- comments
- analytics&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;For the Comments and Analytics sections, you&amp;#8217;ll want to set yourself up some external services. That&amp;#8217;ll be the next ten minutes, unless you&amp;#8217;ve done this before. First, head to &lt;a href='http://disqus.com/'&gt;Disqus&lt;/a&gt; and create an account for yourself there, and register your site. Add your site shortname to the configuration. Next, head to &lt;a href='http://www.google.com/analytics/'&gt;Google Analytics&lt;/a&gt; and sign up if you haven&amp;#8217;t already. Create a new account to track your website. You should recieve a tracking code that looks something like &lt;code&gt;UA-12345-1&lt;/code&gt;. Add that to the analytics section.&lt;/p&gt;

&lt;p&gt;Your blog should be set up, at least initially. Commit and push your repository and check it online. Time to start your first post!&lt;/p&gt;

&lt;h2 id='next_steps'&gt;Next Steps&lt;/h2&gt;

&lt;p&gt;Jekyll Bootstrap comes with a sample post in the &lt;code&gt;_posts/core-samples&lt;/code&gt; directory. You&amp;#8217;ll want to read this, as it contains useful information on how the Jekyll engine works. After you&amp;#8217;ve read through it, delete the entire &lt;code&gt;core-samples&lt;/code&gt; directory as you&amp;#8217;ll want to start your blog fresh. You can start the first post from the commandline; for example, this is the command I used to create this post: &lt;code&gt;rake post title=&amp;quot;Deploying a blog to Github in 30 minutes or less&amp;quot;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you&amp;#8217;ve been chugging along, you should reach this point in just around 30 minutes. Now, comes the hard part: What do you write about? Unfortunately, I can&amp;#8217;t help you there.&lt;/p&gt;</description>
                <link>http://urthen.github.com/2013/04/20/deploying-a-blog-to-github-in-30-minutes-or-less</link>
                <guid>http://urthen.github.com/2013/04/20/deploying-a-blog-to-github-in-30-minutes-or-less</guid>
                <pubDate>2013-04-20T00:00:00-07:00</pubDate>
        </item>


</channel>
</rss>
