Skip to main content
32 of 43
deleted 10140 characters in body
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60

Soapi.CS : A rich fluent .NET Stack Overflow API client library - complete. finally.

##Soapi.CS for .Net / Silverlight / Windows Phone 7 / Mono Quick and Easy:

int epicBadge = 145;

var epicMicrosoftUsersAndWhatTheyLike =
    SO.Badges.ById(epicBadge).PageCount(-1)
    .Where(u => (u.AboutMe ?? "")
    .IndexOf("Microsoft", StringComparison.OrdinalIgnoreCase) > -1)
    .Select(u => new
        {
            u.DisplayName,
            u.Reputation,
            FavoriteQuestion = u.Favorites.FirstOrDefault()
        });

foreach (var user in epicMicrosoftUsersAndWhatTheyLike)
{
    Console.WriteLine("{0} [{1}]\r\n\tlikes\r\n\t{2}", user.DisplayName,
       user.Reputation, user.FavoriteQuestion != null ? user.FavoriteQuestion.Title 
       + " - by " + user.FavoriteQuestion.Owner.DisplayName + " [" + 
       user.FavoriteQuestion.Owner.Reputation + "]" : "");
}

// if you can think it, you can get it.

Output

     -->http://api.stackoverflow.com/1.0/badges/145?pagesize=100&key=qgAq_KfDu0KYzlNG-qaTuw
     -->http://api.stackoverflow.com/1.0/badges/145?page=1&pagesize=100&key=qgAq_KfDu0KYzlNG-qaTuw
     -->http://api.stackoverflow.com/1.0/users/38360/favorites?key=qgAq_KfDu0KYzlNG-qaTuw
     -->http://api.stackoverflow.com/1.0/users/33015?key=qgAq_KfDu0KYzlNG-qaTuw
     
Aaronaught [33621]
    likes
    Most useful free .NET libraries? - by Binoj Antony [3942]
    
     -->http://api.stackoverflow.com/1.0/users/1583/favorites?key=qgAq_KfDu0KYzlNG-qaTuw
     -->http://api.stackoverflow.com/1.0/users/1583?key=qgAq_KfDu0KYzlNG-qaTuw
     
Oded [42302]
    likes
    What is the single most effective thing you did to improve your programming skills? - by Oded [42302]
    
     -->http://api.stackoverflow.com/1.0/users/3153/favorites?key=qgAq_KfDu0KYzlNG-qaTuw
     -->http://api.stackoverflow.com/1.0/users/11898?key=qgAq_KfDu0KYzlNG-qaTuw
     
Brian R. Bondy [58385]
    likes
    What techniques can be used to speed up C++ compilation times? - by Scott Langham [6867]
    
     -->http://api.stackoverflow.com/1.0/users/113794/favorites?key=qgAq_KfDu0KYzlNG-qaTuw
     -->http://api.stackoverflow.com/1.0/users/232289?key=qgAq_KfDu0KYzlNG-qaTuw
     
Rubens Farias [18490]
    likes
    Poison Message Handling in WCF MSMQ 4.0 - by srinivas akella [6]
    
     -->http://api.stackoverflow.com/1.0/users/88656/favorites?key=qgAq_KfDu0KYzlNG-qaTuw
     -->http://api.stackoverflow.com/1.0/users/250155?key=qgAq_KfDu0KYzlNG-qaTuw
     
Eric Lippert [54147]
    likes
    More about Virtual / new...plus interfaces! - by Bruno [37]
    
     -->http://api.stackoverflow.com/1.0/users/76337/favorites?key=qgAq_KfDu0KYzlNG-qaTuw
     -->http://api.stackoverflow.com/1.0/users/85040?key=qgAq_KfDu0KYzlNG-qaTuw
     
John Saunders [53227]
    likes
    Test Client for testing WCF Rest services or just use browser? - by mark smith [1316]
    
     -->http://api.stackoverflow.com/1.0/users/22656/favorites?key=qgAq_KfDu0KYzlNG-qaTuw
     -->http://api.stackoverflow.com/1.0/users/8817?key=qgAq_KfDu0KYzlNG-qaTuw
     
Jon Skeet [203169]
    likes
    What are five things you hate about your favorite language? - by brian d foy [36312]
    
     -->http://api.stackoverflow.com/1.0/users/23283/favorites?key=qgAq_KfDu0KYzlNG-qaTuw
     -->http://api.stackoverflow.com/1.0/users/194?key=qgAq_KfDu0KYzlNG-qaTuw
     
JaredPar [106079]
    likes
    Marshal C++ struct array into C# - by Adam Haile [6173]
    
     -->http://api.stackoverflow.com/1.0/users/3043/favorites?key=qgAq_KfDu0KYzlNG-qaTuw
     -->http://api.stackoverflow.com/1.0/users/40406?key=qgAq_KfDu0KYzlNG-qaTuw
     
Joel Coehoorn [83038]
    likes
    java for c# developers - by Pita.O [477]
    
     -->http://api.stackoverflow.com/1.0/users/65358/favorites?key=qgAq_KfDu0KYzlNG-qaTuw
     -->http://api.stackoverflow.com/1.0/users/83264?key=qgAq_KfDu0KYzlNG-qaTuw
     
Reed Copsey [90547]
    likes
    Large Object Heap Fragmentation - by Paul Ruane [1978]
    
     -->http://api.stackoverflow.com/1.0/users/111335/favorites?key=qgAq_KfDu0KYzlNG-qaTuw
     -->http://api.stackoverflow.com/1.0/users/179972?key=qgAq_KfDu0KYzlNG-qaTuw
     
Pavel Minaev [29572]
    likes
    New programming jargon you coined? - by jdk [4523]


##About

A robust, easy to use, strongly typed, end-to-end StackOverflow API Client Library.

Out of the box, Soapi provides you with a robust client library that abstracts away most all of the messy details of consuming the API and lets you concentrate on implementing your ideas.

A few features include:

  • A fully relational model of the API data set exposed via a fully 'dot navigable' IEnumerable (LINQ) implementation. Simply tell Soapi what you want and it will get it for you.

    e.g. "On my first question, from the author of the first comment, get the first page of comments by that person on any post"

    my.Questions.First().Comments.First().Owner.Comments.ToList();

    (yes this is a real expression that returns the data as expressed!)

  • Full coverage of the API, all routes and all parameters with an intuitive syntax.

  • Strongly typed Domain Data Objects for all API data structures.

  • Eager and Lazy Loading of 'stub' objects. Eager\Lazy loading may be disabled.

  • When finer grained control of requests is desired, the core RouteMap objects may be leveraged to request data from any of the API paths using all available parameters as documented on the help pages.

  • A rich Asynchronous implementation.

  • A configurable request cache to reduce unnecessary network traffic and to simplify your usage logic. There is no need to go out of your way to be frugal. You may set a distinct cache duration for any particular route.

  • A configurable request throttle to ensure compliance with the api terms of usage and to simplify your code in that you do not have to worry about and respond to 50X errors.

    The RequestCache and Throttled Queue are thread-safe, so can make as many requests as you like from as many threads as you like as fast as you like and not worry about abusing the api or having to write reams of management/compensation code.

  • Configurable retry threshold that will, by default, make up to 3 attempts to retrieve a request before failing. Every request made by Soapi is properly formed and directed so most any http error will be the result of a timeout or other network infrastructure. A retry buffer provides a level of fault tolerance that you can rely on.

  • An almost identical javascript library, Soapi.JS, that will enable you to leverage your server cycles and bandwidth for only those tasks that require it and offload things like status updates to the client's browser.

##License

Licensed GPL Version 2 license.

##Platforms

  • .NET 3.5
  • .NET 4.0
  • Silverlight 3
  • Silverlight 4
  • Windows Phone 7
  • Mono

##Download

Source code lives @ http://soapics.codeplex.com. Binary releases are forthcoming.

codeplex is acting up again.

get the source @ http://bitbucket.org/bitpusher/soapi.cs

The source is C# 3.5. and includes projects and solutions for the following IDEs

  • Visual Studio 2008
  • Visual Studio 2010
  • ModoDevelop 2.4

##Documentation

Full documentation is available at http://soapi.info/help/cs/index.aspx

##Sample Code / Usage Examples Sample code and usage examples will be added as answers to this question.

The CS/SL/WP7/MONO libraries all compile the same code and with the exception of environmental considerations of Silverlight, the code samples are valid for all libraries.

You may also find guidance in the test suites.

##Contact

This library is currently the effort of me, Sky Sanders (code poet) and can be reached at gmail - sky.sanders

Any who are interested in improving this library are welcome.


Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60