APIMASH Chuck Norris Starter Kit

June 6, 2013

The APIMASH Chuck Norris Starter Kit is a XAML/C# Windows 8 app that demonstrates calling the Internet Chuck Norris API.

Note: You do not download the Chuck Norris Starter Kit…it downloads you!

The ICNDb Web Service returns a simple JSON payload containing a hard-hitting nugget of humor that is deserialized and displayed on the User Interface.

For an overview of the APIMASH Starter Kits and their architecture see this article.

This article provides an overview of the starter kit so that you can learn how to call web services, deserialize JSON to C# and bind to UI controls. By digging into the APIMASH Starter Kits I hope that you are inspired to create your own unique, compelling Windows 8 app, maybe one that leverages the Internet Chuck Norris API.

Features

Requirements

Setup

Updating APIMASHLib

APIMASHLib by default is using a third party library for JSON deserialization, JSON.NET. The APIMASHLib project in the Rotten Tomatoes Starter Kit Solution will show that the Newtonsoft.Json reference is broken so you will need to update that reference.

image

There are 2 ways to update the reference to the Newtonsoft JSON.NET library in the APIMASHLIb project; a) Use NuGet, b) download the Zip from Json.codeplex.com and reference the DLL in the WinRT folder.

Using NuGet

To use NuGet, in Visual Studio navigate the menu Tools > Library Package Manager > Manage NuGet Package for Solution.

image

Search for Json.NET and install. Request to add it to the APIMASHLib project.

image

Customization

There are currently 2 apps in the Windows 8 Store that I am aware of that have leveraged the Chuck Norris Starter Kit. There can never be too many Chuck Norris apps and so we are only just getting started.

image

Touch Guy Jokes

image

Chuck Norris LOL

Using the Chuck Norris API

Using the Chuck Norris API is very straightforward. To request a random joke invoke this URL:

http://api.icndb.com/jokes/random

The API returns a simple JSON payload:

{ 
    "type": "success", 
    "value": 
    { 
        "id": 268, 
        "joke": "Time waits for no man. Unless that man is Chuck Norris." 
        "categories": []
    } 
}

In order to deserialize this payload we define the following C# class that maps to this structure:

[DataContract]
public class CNorrisJoke
{
    [DataMember(Name="type")]
    public string Type { get; set; }

    [DataMember(Name="value")]
    public JokeValue Value { get; set; }
}

[DataContract]
public class JokeValue
{
    [DataMember(Name="id")]
    public string Id { get; set; }

    [DataMember(Name="joke")]
    public string Joke { get; set; }

    [DataMember(Name="caegories")]
    public string[] Categories { get; set; }
}

Note the use of the DataContract and DataMember attributes that provide the mapping between the JSON notation and the C# class members.

See this article for details on JSON Deserialization for C# developers

Changing the name of the main character

The API permits changing the name of the main character when fetching a joke. To do this, use the following GET parameters. To retrieve one random joke with main character called “John Doe”, fetch the URL:

http://api.icndb.com/jokes/random?firstName=John&lastName=Doe

This feature allows you to leverage the joke database in scenarios where you have someone’s name such a friend list from Facebook or Twitter.

Conclusion

Building compelling apps requires compelling data. Open Data API’s are an excellent way to gather and mashup new experiences for end users. To learn more attend one of our in-person workshops or one of our Webcast Series on the APIMASH Starter Kits.  Each session will run from Noon – 1pm EDT. Attend one or all four webcasts, you decide. For more details or to register, choose a webcast below.

6/5/2013 | Exploring the Mashery APIs

Register
In this webcast you will learn how to develop Windows 8 apps using Mashery API’s such as Tom-Tom, Edmunds, Rotten Tomatoes and Active.com. Amit Jotwani from Mashery will join us to provide an overview of Mashery the industry leader in API management. We will cover how to access these web service API’s and then deserialize the response into a set of runtime objects that you can bind to Windows 8 UX Controls to create a compelling experience.

6/12/2013 | Exploring the Social Networking APIs

Register
In this webcast you will learn how to develop Windows 8 apps using the Twitter, Meetup and Facebook APIs. Twitter, Meetup and Facebook are the premier social networking sites and their API’s provide access to Tweets, Meetups and Friends. What a great combination!

6/19/2013 | Exploring the Yelp API

Register
In this webcast you will learn how to develop Windows 8 apps using the Yelp API. Yelp is a local business directory service and review site with social networking features. People use Yelp to search for everything from the city’s tastiest burger to the most renowned cardiologist.

6/25/2013 | Exploring the Bing Maps API

Register
In this webcast you will learn how to develop Windows 8 apps using the Bing Maps API. Bing Maps gives you a rich set of tools to help you create amazing map experiences perfect for mash-ups.

Lastly don’t forget to check out the “Keep the Cash Rewards” offer to see how you can get $100 for publishing your app(s) in the Windows Store and/or Windows Phone Store. Publish your app before June 30, 2013 and you can get a $100 virtual Visa card for every qualified app you enter (up to $2000*). Learn more.

-bob

4 Comments
  • Pingback: APIMASH EchoNest Starter Kit | 42 base 13

  • Pingback: APIMASH GeoNames Wikipedia API Walkthrough - DevFish on MSDN ...>««(o>... - Site Home - MSDN Blogs

  • Pingback: APIMASH Chuck Norris Starter Kit for Windows Phone 8 | BOB FAMILIAR

  • Pingback: Dew Drop – June 7, 2013 (#1,563) | Alvin Ashcraft's Morning Dew

  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    *



    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    More in Development (6 of 10 articles)
    screenshot_05282013_161448_thumb.png