Consuming the Stack Exchange API with C#


Need I say anything about the awesome that is Stack Overflow? Okay, maybe adding a walk-through of consuming its API with C# needs to be said...

Stack Exchange API

Two weeks ago I was playing around with the Stack Exchange API to see if it was easy to build a custom flair application. You know, this little guy:


How hard can it be to retrieve a user’s profile, badge count and reputation updates? Surely, Stack Exchange has an API. And they do…and it’s pretty easy to use. Let’s quickly cobble together a small sample application.

Table Of Contents

  • Introduction
  • API Usage
  • User Profile
  • Sending Requests
  • Reputation Changes

The post goes into some nice depth; from getting into the API;

API Usage

You can find the documentation for the Stack Exchange API here:

At the time of writing the latest release is v1.1, but a draft specification for version 2.0 has just been released.

What do you need to know about the API?

  • It’s read-only
  • All API responses are JSON
  • All responses are GZIP’d
  • API usage is throttled by IP address

To the tools/libraries you'll need;

So what do we need to be able to use the API?

  • It talks JSON? Fire up NuGet and get the popular Json.NET library.
  • We’ll need to issue requests. Let’s keep it simple and use the HttpWebRequest class
  • All responses are GZIP’d? Luckily the .NET framework provides us with the GZipStream class.

To writing code...



And in the end, some output;


BTW, to download the full sample, head over to his download page;




So if you're interested in the Stack Overflow/Stack Exchange API, or just consuming a web service API that uses JSON, this project is waiting for you...

The Discussion

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to send us feedback you can Contact Us.