1. Glenn Ruysschaert's Avatar
    Hello, I found that a lot of the code necessary to communicate with a JSON API is always the same. So I compiled the code I frequently use into a NuGet package and released it.

    It is the second version, so it might be buggy and doesnt have that many features yet. Plus it's my very first NuGet package I made, and only spent about 3 hours on it (so it's kind of a trial). I decided to release it already anyway, so it might help others code faster.

    The usage is really simple, for example to get the word of the day on Urban Dictionary I have this class:
    Code:
    public class WordOfTheDay
    {
        public string word { get; set; }
        public string meaning { get; set; }
    }
    Then all I need to do is use this line of code, and I will get the word of the day in the class I gave.
    Code:
    WordOfTheDay wotd = await JsonHttp.Get<WordOfTheDay>(new Uri("http://urban-word-of-the-day.herokuapp.com/today"));
    That's it! No more messing with HttpClient, handlers, ... As for now it obviously only supports basic functionality, but I'm open to requests.

    It's possible to add some extra options:
    Code:
    JsonHttp.Options options = new JsonHttp.Options()
    {
        AllowAutoRedirect = true,
        DefaultRequestHeaders = new Dictionary<string, string>(),
        AddMediaTypeWithQualityHeadersJson = true,
        UseLocationHeaderForRedirects = true
    };
    WordOfTheDay wotd = await JsonHttp.Get<WordOfTheDay>(new Uri("http://urban-word-of-the-day.herokuapp.com/today"), options);
    For POST/PUT you can also let a class be automatically converted to JSON and sent with your request
    Code:
    WordOfTheDay toPost = new WordOfTheDay()
     {
         word = "test",
         meaning = "something"
     };
     WordOfTheDay wotdPost = await JsonHttp.Post<WordOfTheDay>(new Uri(""), toPost, options);
    You can try it out here (or look for JsonHttp).
    Source code and documentation here on GitHub
    vander09 likes this.
    04-19-2016 02:46 AM
  2. owensdj's Avatar
    Looks like JsonHttp is going to be really good.
    04-19-2016 09:10 AM
  3. Glenn Ruysschaert's Avatar
    Thanks, I hope it will be
    04-21-2016 04:05 AM

Similar Threads

  1. Replies: 5
    Last Post: 04-20-2016, 01:19 AM
  2. Windows Camera app for Mobile: Issues with Living Images, any advice?
    By Shanmuga Subramanian in forum Windows 10 Mobile
    Replies: 1
    Last Post: 04-19-2016, 02:12 AM
  3. App for google-drive?
    By Windows Central Question in forum Ask a Question
    Replies: 1
    Last Post: 04-19-2016, 12:21 AM
  4. Beta impressions: Does Battleborn make the case for the first-person MOBA?
    By WindowsCentral.com in forum Windows Central News Discussion
    Replies: 0
    Last Post: 04-18-2016, 03:42 PM
LINK TO POST COPIED TO CLIPBOARD