Nov 242016
 November 24, 2016  Posted by at 1:32 pm C# & F#, Dev Environment  Add comments

I have been working on my wardrobe application and added the weather feature a few days ago. I try to find time to finish the application, but it’s going slower than I wish it did. Last Saturday I moved to a new apartment and as I have been unpacking I have also sorted my clothes and the app would have been handy to have. Still need to find washable and small passive NFC tags so it’s faster to register laundry status on the item. If you know where I can find waterproof (washing machine proof!) tags please do let me know!

I thought I’d share with you how simple it is to get started with a weather API I came across, OpenWeatherMap. It’s free as long as calls per minute is below 60 plus Creative Commons license CC BY-SA 4.0 requirements. Double check this, as these things change with time and this post might not 😉

Let’s get started!
Create an account at OpenWeatherMap


Under API Keys you will find your default key- but you can generate more keys if you want to.


Now simply make the calls as specified in the documentation.


The rules are simple, the majority of the calls start with:
And after that follows the details, for example
and then a query string
and they should always contain the key:

I used JSON.Net to deserialize the data, after mapping the JSON to C# objects. With the latter I cheated- I grabbed the JSON data and then selected Edit => Paste Special => Paste JSON as classes in Visual Studio and voilá- I had the classes.


I then use Resharper and ‘Fix naming in file’ to get the naming to use the pascal case capitalization style. Then I use Resharper again to extract the types to their own classes in a folder.

There we go- weather in five minutes.


  2 Responses to “Weather API in five minutes”

  1. or simple: curl

  2. I have to admit I got a little excited when I saw that this post’s category is ‘C# & F#’, and then realised there was actually no F#. Well, maybe next time 😉

    Anyway, since I (found an opportunity and) brought it up, here’s a tiny bit of F#: the Wind type in F# would look like this: type wind = { speed : float; deg : int }.

    To be fair though, C# does have ‘record’ or struct types too and if you wanted to optimise your JSON types you’d probably end up with the equivalent C# public struct Wind { public float speed; public int deg }.

 Leave a Reply

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=""> <s> <strike> <strong>



What is 10 + 12 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)