Soapi.CS : A fully relational fluent .NET Stack Exchange API client library
Posted
by
Sky Sanders
on Stackapps
See other posts from Stackapps
or by Sky Sanders
Published on 2010-05-31T09:54:17Z
Indexed on
2010/12/27
1:58 UTC
Read the original article
Hit count: 932
Soapi.CS for .Net / Silverlight / Windows Phone 7 / Mono
as easy as breathing...:
var context = new ApiContext(apiKey).Initialize(false);
Question thisPost = context.Official
.StackApps
.Questions.ById(386)
.WithComments(true)
.First();
Console.WriteLine(thisPost.Title);
thisPost
.Owner
.Questions
.PageSize(5)
.Sort(PostSort.Votes)
.ToList()
.ForEach(q=>
{
Console.WriteLine("\t" + q.Score + "\t" + q.Title);
q.Timeline.ToList().ForEach(t=>
Console.WriteLine("\t\t" +
t.TimelineType + "\t" + t.Owner.DisplayName));
Console.WriteLine();
});
// if you can think it, you can get it.
Output
Soapi.CS : A fully relational fluent .NET Stack Exchange API client library 21 Soapi.CS : A fully relational fluent .NET Stack Exchange API client library Revision code poet Revision code poet Votes code poet Votes code poet Revision code poet Revision code poet Revision code poet Votes code poet Votes code poet Votes code poet Revision code poet Revision code poet Revision code poet Revision code poet Revision code poet Revision code poet Revision code poet Revision code poet Revision code poet Revision code poet Votes code poet Comment code poet Revision code poet Votes code poet Revision code poet Revision code poet Revision code poet Answer code poet Revision code poet Revision code poet 14 SOAPI-WATCH: A realtime service that notifies subscribers via twitter when the API changes in any way. Votes code poet Revision code poet Votes code poet Comment code poet Comment code poet Comment code poet Votes lfoust Votes code poet Comment code poet Comment code poet Comment code poet Comment code poet Revision code poet Comment lfoust Votes code poet Revision code poet Votes code poet Votes lfoust Votes code poet Revision code poet Comment Dave DeLong Revision code poet Revision code poet Votes code poet Comment lfoust Comment Dave DeLong Comment lfoust Comment lfoust Comment Dave DeLong Revision code poet 11 SOAPI-EXPLORE: Self-updating single page JavaSript API test harness Votes code poet Votes code poet Votes code poet Votes code poet Votes code poet Comment code poet Revision code poet Votes code poet Revision code poet Revision code poet Revision code poet Comment code poet Revision code poet Votes code poet Comment code poet Question code poet Votes code poet 11 Soapi.JS V1.0: fluent JavaScript wrapper for the StackOverflow API Comment George Edison Comment George Edison Comment George Edison Comment George Edison Comment George Edison Comment George Edison Answer George Edison Votes code poet Votes code poet Votes code poet Votes code poet Revision code poet Revision code poet Answer code poet Comment code poet Revision code poet Comment code poet Comment code poet Comment code poet Revision code poet Revision code poet Votes code poet Votes code poet Votes code poet Votes code poet Comment code poet Comment code poet Comment code poet Comment code poet Comment code poet 9 SOAPI-DIFF: Your app broke? Check SOAPI-DIFF to find out what changed in the API Votes code poet Revision code poet Comment Dennis Williamson Answer Dennis Williamson Votes code poet Votes Dennis Williamson Comment code poet Question code poet Votes code poet
About
A robust, fully relational, 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, and it's full figured big brother, Soapi.JS2, 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.
- Why is Soapi.CS GPL?
- Can I get an LGPL license for Soapi.CS? (hint: probably)
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 and binaries @ http://bitbucket.org/bitpusher/soapi.cs/downloads
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.
- Full API Coverage all API routes are covered
- Full Parameter Parity If the API exposes it, Soapi giftwraps it for you.
- Building a simple app with Soapi.CS - a simple app that gathers all traces of a user in the whole stackiverse.
- Fluent Configuration - Setting up a Soapi.ApiContext could not be easier
- Bulk Data Import - A tiny app that quickly loads a SQLite data file with all users in the stackiverse.
- Paged Results - Soapi.CS transparently handles multi-page operations.
- Asynchronous Requests - Soapi.CS provides a rich asynchronous model that is especially useful when writing api apps in Silverlight or Windows Phone 7.
- Caching and Throttling - how and why
Apps that use Soapi.CS
- Soapi.FindUser - .net utility for locating a user anywhere in the stackiverse
- Soapi.Explore - The entire API at your command
- Soapi.LastSeen - List users by last access time
- Add your app/site here - I know you are out there ;-) if you are not comfortable editing this post, simply add a comment and I will add it.
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.
More information on the SOAPI eco-system.
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.
Support Soapi
You can help support this project by voting for Soapi's Open Source Ad post
For more information about the origins of Soapi.CS and the rest of the Soapi eco-system see What is Soapi and why should I care?
© Stackapps or respective owner