SteamWebAPI2 .NET Library

repository·master·Indexed 42 days ago

https://github.com/babelshift/steamwebapi2

A strongly-typed .NET wrapper for the Steam Web API that standardizes JSON responses, converts UNIX timestamps to DateTime, and provides a unified SteamId class. It supports public-facing endpoints at api.steampowered.com via the SteamWebInterfaceFactory.

Tokens
1.1K
Snippets
4
Records
4
Agent score
5%

What's inside SteamWebAPI2

  1. Understand the SteamWebResponse object

    master

    Every method call in the library returns a SteamWebResponse<T> object. This object wraps the API payload and includes HTTP metadata. The generic type T maps to the specific payload returned by the Steam Web API.

    // Example of accessing response properties
    var response = await steamInterface.GetPlayerSummaryAsync(steamId);
    
    var data = response.Data;               // The actual API payload (T)
    var contentLength = response.ContentLength; // HTTP ContentLength header
    var contentType = response.ContentType;     // HTTP ContentType header
    var charset = response.ContentTypeCharSet;  // HTTP ContentType charset header
    var expires = response.Expires;             // HTTP Expires header
    var lastModified = response.LastModified;   // HTTP LastModified header
  2. How to use SteamWebAPI2

    master

    To use the library, follow these steps:

    1. Obtain a Steam Web API developer key from Steam Community. Keep this key secret.
    2. Instantiate a SteamWebInterfaceFactory using your API key.
    3. Use the factory to create specific endpoint interface classes (e.g., SteamUser) by passing an HttpClient instance. This allows you to maintain control over the HttpClient lifecycle.
    4. Call methods on the created interface class to interact with the Steam Web API.

    Note: This library only supports the public-facing API at api.steampowered.com. It does not support partner-only endpoints located at partner.steam-api.com.

    // 1. Initialize the factory with your API key
    var webInterfaceFactory = new SteamWebInterfaceFactory("<dev api key here>");
    
    // 2. Create an interface (e.g., SteamUser) using an HttpClient
    var steamInterface = webInterfaceFactory.CreateSteamWebInterface<SteamUser>(new HttpClient());
    
    // 3. Call methods (e.g., GetPlayerSummaryAsync)
    var playerSummaryResponse = await steamInterface.GetPlayerSummaryAsync(<steamIdHere>);
    
    // 4. Access the data
    var playerSummaryData = playerSummaryResponse.Data;
  3. Reference: SteamWebResponse fields

    master

    The following fields are available on the SteamWebResponse object returned by interface methods:

    | Field | Type | Description |
    | ------------------ | :--- | -------------------------------------------------- |
    | Data | T | Maps to the payload returned by the Steam Web API. |
    | ContentLength | long? | Maps to the HTTP ContentLength header. |
    | ContentType | string | Maps to the HTTP ContentType header. |
    | ContentTypeCharSet | string | Maps to the HTTP ContentType charset header. |
    | Expires | DateTimeOffset? | Maps to the HTTP Expires header. Optional. |
    | LastModified | DateTimeOffset? | Maps to the HTTP LastModified header. Optional |