Friday, February 3, 2012

C# example search GitHub API for user

Here follows simple example how to search Github for user with C# WebRequest and Github API V2
using System;
using System.Net;
using System.IO;

namespace SimpleGitHubAPI
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            HttpWebRequest request = WebRequest.Create ("https://github.com/api/v2/json/user/search/dkucinskas") as HttpWebRequest;
            request.Method = "GET";
            request.Proxy = null;
   
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) 
            {
                using (StreamReader reader = new StreamReader(response.GetResponseStream())) 
                {
                    Console.Write(reader.ReadToEnd());      
                }
            }
        }
    }
}
Have fun :)