StackExchange.NET

Easy access to the StackExchange APi's with virtually no boilerplate code required


Keywords
StackExchange, Github, C#, Client, Library, client-library, csharp, dotnet-library, dotnet-standard, stackoverflow-api
License
MIT
Install
Install-Package StackExchange.NET -Version 1.1.0

Documentation

StackExchange.NET

All Contributors

 _____ _             _    ______          _                              _   _ ______ _______ 
 / ____| |           | |  |  ____|        | |                            | \ | |  ____|__   __|
| (___ | |_ __ _  ___| | _| |__  __  _____| |__   __ _ _ __   __ _  ___  |  \| | |__     | |   
 \___ \| __/ _` |/ __| |/ /  __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \ | . ` |  __|    | |   
 ____) | || (_| | (__|   <| |____ >  < (__| | | | (_| | | | | (_| |  __/_| |\  | |____   | |   
|_____/ \__\__,_|\___|_|\_\______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___(_)_| \_|______|  |_|   
                                                              __/ |                            
                                                             |___/                             
 

Created by Hari Haran

Overview

StackExchange.NET is a .NET Standard managed library that provides easy access to the StackExchange APi's with virtually no boilerplate code required.

Currently the library supports 18 Endpoints ( As on 11:09:2019) listed in the API Docs. I will be covering all the other endpoints as well, except those that require Auth.

StackExchange.NET is FOSS (MIT License) and written entirely in c#.

Contributors

Pandiyan Murugan
Pandiyan Murugan

📖

Usage

To create a new API instance provide the apikey. If you need a new key check docs

  var client = new StackExchangeClient("yourApiKey");

You can easily find the relevant method under your preferred section. For example, lets say i want to GetAllPosts It can be simply achived by

var posts = client.Posts.GetAllPosts(postFilter);

Noticed the postFiler parameter. Similar to that, each method has its own parameter to filter the results from the api. The Post Filter object can also be accessed like this

var postFilter = new PostFilter()
{
    Sort = PostSort.Creation
};

Parameter Filters

There are different types of parameter filter objects available. Each Parent Method will have its own filter. Example : All the clients.Comments will accept a CommentFilter()

  • AnswerFilters
  • BadgeFilters
  • CommentFilter
  • PostFilter

ChangeLogs

Verison 1.1

  • Improved overall code quality using Fluent API Url Builders

  • Removed all Hardcoded API URL's

  • More Clean code

    # Before V.0 (Initial commit)
    
    var apiParams = filters.GetQueryParams();
    var url = $"{_baseApiUrl}/answers?key={_apiKey}&{apiParams}";
    var response = _httpClient.GetAsync(url).Result.Content.ReadAsStringAsync().Result;
    var apiResult = response.DeserializeJson<Data<Answer>>().ValidateApiResponse();
    return apiResult;
    
    # After V1.1
    
    var url = ApiUrlBuilder
                .Initialize(_apiKey)
                .ForClient(ClientType.Answers)
                .WithFilter(filters)
                .GetApiUrl();
    var response = _httpClient.GetAsync(url).Result
                .ReadAsJsonAsync<Data<Answer>>()
                .ValidateApiResponse();
    return response;