API Versioning in ASP.NET Web API 2.1

Thanks to new changes to Attribute Routing in ASP.NET Web API 2.1 there are two easy ways to version your RESTful API now. Let’s take a look at two approaches we can use for API versioning in Web API 2.1:

Approach 1
  1. Separate your controllers of different versions by file naming (e.g. MyV1Controller, MyV2Controller) or by namespaces (e.g. MyApi.V1.MyController and MyApi.V2.MyController)
  2. Use VersionedRoute atrribue for your controller:
    [VersionedRoute("api/my", 1)]
    public class MyV1Controller : ApiController { ... }
    [VersionedRoute("api/my", 2)]
    public class MyV2Controller : ApiController { ... }

    Now client should include the following header item in the request:
    api-version: 2

Approach 2

Another approach to have version number in the URI is to use RoutePrefix instead as follows:

[RoutePrefix("api/v1/my")]
public class MyV1Controller : ApiController { ... }
[RoutePrefix("api/v2/my")]
public class MyV2Controller : ApiController { ... }

It’s a little bit easier because there is no need to set API Version header but considered as a second class solution when talking about best practices ;-)

Dig more!

 

Automate Your Social Content Publishing

There are many people in the world who use powerful social media tools like Twitter, Facebook, etc to communicate with  their friends, find interesting contents, to be the first to get notified of the breaking news and more. Many of us who are active in any field are using these tools to produce and publish contents as well looking at the fun side of these tools.

Personally I’m accustomed to share interesting links, apps, quotes or any other thing I find during my daily web surfing and let my friends and followers enjoy them too. You may have many feeds which you take a look every morning and select some of them to read and maybe share; but it’s not a good idea to share them all at once and flood your friends timeline with consecutive tweets or status updates! This will also decrease the chance for them to be read.

Said all these to introduce some services which can help you schedule such updates in an easy and productive way; let’s start with the problem:

I want to tweet every single item which I star in my Google Reader but not at once, schedule them to publish during the upcoming hours.

My solution is to use various services to accomplish this:

  • I will use IFTTT to automate publishing contents which I star in Google Reader.
  • I will use Buffer to schedule tweet publishing throughout the day.
  • I will use Tweriod to find out which hours are the best to schedule my tweets to send out.

Now let me explain more; First of all go to bufferapp.com and signup; it lets you send and update from their website or schedule it based on the hours you specify in the Settings page. You can also authorize this app with your bit.ly account so that it posts links with your own custom URL shortenner (like mine: go.mahdi.ws); then go to ifttt.com and signup; IFTTT lets you connect various service together and run them as automated scheduled tasks. In our case you need to select Buffer and Google Reader from Channels and add them to your channels; after that you can create your own recipe to post starred item in Google Reader to Buffer or use my ready recipe for this.

Congratulations! You’re done! Starting from now, all your starred items in Google reader will be automatically posted to your Buffer queue and will be published during the day.

There is one more cool optional step to use if you like ;-) Tweriod gives you a report on what are the best hours to send out your tweets based on various parameters; sign up and wait for your first report to arrive in your mailbox; then you can adjust the best posting hours for your tweets just by connecting your Buffer account to Tweroid and let it do its job!

New Domain And My Tumblr Blog!

Due to some personal reasons I changed my main domain name to mahdi.ws and will use this as my main address; mahdi.ws is still mine and valid and is redirected here. I changed FeedBurner address and if you’ve subscribed to my feed you don’t need to change anything.

In addition, I started my Tumblr blog at daily.mahdi.ws in order to share some small pieces of my feelings, things I read, listen to or watch daily. Follow me there :-)

Slides of My Talk at Open Web Platform Seminar: “Microsoft, Web Standards and Open Source Software”

Today I had a session at the first Open Web Platform Seminar in Tehran (follow on Twitter #owp1391) and talked about ”Microsoft, Web Standards and Open Source Software“.

As the title of my talk implies, I tried to cover two topics during my talk:

  • Microsoft’s efforts to support web standards in its products from server side technologies and tools (ASP.NET and Visual Studio) to turning IE into a modern and standard web browser.
  • Microsoft and recent activities to support OSS and help the users enjoy the best of both worlds: Microsoft products and tools plus open source products which are great when used side by side with Microsoft tools.

Despite this fact that slides of my talk is not that much useful without my explanations, you can download them from here or view on SlideShare.