Helldivers 2 API

repository·master·Indexed 42 days ago

https://github.com/helldivers-2/api

A community-driven API providing Helldivers 2 game data in JSON format. It allows developers to build third-party applications without directly hitting official game servers. The API features a base URL at https://api.helldivers2.dev, supports OpenAPI specifications, and provides options for self-hosting via Docker with customizable rate limits and authentication.

Tokens
2.3K
Snippets
8
Records
16
Agent score
55%

What's inside Helldivers 2 API

  1. Understand the Helldivers_2_SourceGen project structure

    master

    The repository is organized into three distinct projects to demonstrate different aspects of Roslyn source generators:

    1. Helldivers_2_SourceGen: A .NET Standard project containing the actual generator implementations. Note: You must build this project to see the generated code in your IDE.
      • SampleSourceGenerator.cs: Generates C# classes based on a text file (e.g., a DDD ubiquitous language registry).
      • SampleIncrementalSourceGenerator.cs: An incremental generator that creates custom reports based on class properties. It targets classes annotated with the Generators.ReportAttribute attribute.
    2. Helldivers_2_SourceGen.Sample: A consumer project that references the generators. It uses specific ProjectReference parameters to ensure the project is treated as a set of source generators.
    3. Helldivers_2_SourceGen.Tests: A suite of unit tests designed for developing and verifying language-related features.
  2. Reference the Helldivers_2_SourceGen.Sample project configuration

    master

    When consuming source generators in a .NET project, you must configure the ProjectReference correctly so the compiler treats the referenced project as a source generator rather than a standard library. In this sample, the configuration is located in Helldivers_2_SourceGen.Sample.csproj.

    <!-- Note: The specific XML attributes for the ProjectReference are found in Helldivers_2_SourceGen.Sample.csproj -->
  3. Configure API keys for the self-hosted version

    master

    The API uses an API key mechanism to allow certain clients to bypass standard rate limits. This feature is enabled by default but requires a 32-bit base64-encoded signing key.

    Option 1: Disable API Authentication

    If you do not want to use API keys (e.g., you are managing limits via standard configuration), disable authentication:

    docker run -p 8080:8080 -e "Helldivers__API__Authentication__Enabled=false" helldivers2-api

    Option 2: Enable API Authentication with a Signing Key

    To use API keys, you must provide a signing key via the Helldivers__API__Authentication__SigningKey variable. The key must be 32 bits and base64 encoded.

    docker run -p 8080:8080 -e "Helldivers__API__Authentication__SigningKey=YourSigningKey" helldivers2-api
  4. Get started with the helldivers-2/api

    master

    The helldivers-2/api is a community-driven API providing Helldivers 2 game data in JSON format. It does not require authentication for default usage, though higher rate limits may be available through specific channels.

    Base URL

    Use the following root URL for all requests: https://api.helldivers2.dev

    WARNING

    The root domain has recently changed. Ensure you use https://api.helldivers2.dev to avoid service disruptions.

    API Documentation

    Best Practices

    While an OpenAPI spec for the official ArrowHead studio API is available, it is strongly recommended to use the /raw endpoints of the community wrapper instead of accessing the ArrowHead API directly to reduce load on their servers.

  5. Build the container with OpenAPI support

    master

    By default, OpenAPI specifications are not included in the container image. To enable OpenAPI support, use the OPENAPI=true build argument during the build process.

    docker build --build-arg="OPENAPI=true" -f ./src/Helldivers-2-API/Dockerfile -t helldivers2-api .
  6. Customize API runtime settings via environment variables

    master

    Most API settings (rate limits, synchronization intervals, etc.) can be customized at runtime using environment variables. This overrides the values defined in appsettings.json.

    To override a configuration key, use double underscores (__) as a delimiter for the hierarchy. For example, to override Helldivers:Synchronization:IntervalSeconds, use the environment variable Helldivers__Synchronization__IntervalSeconds.

    Example: Setting the synchronization interval to 10 seconds:

    docker run -p 8080:8080 -e "Helldivers__Synchronization__IntervalSeconds=10" helldivers2-api
  7. Build and run the API container

    master

    You can self-host the API using Docker. This allows for running instances in secured networks or with modified settings like custom rate limits.

    Prerequisites

    Clone the repository including submodules:

    git clone --recurse-submodules https://github.com/helldivers-2/api.git

    Build Steps

    Run the build command from inside the cloned folder:

    docker build -f ./src/Helldivers-2-API/Dockerfile -t helldivers2-api .

    Run the container

    Start the container mapping port 8080:

    docker run -p 8080:8080 helldivers2-api
    WARNING

    If you encounter System.ArgumentNullException: Value cannot be null. (Parameter 's') during startup, you must configure API keys using the steps in Configuring API keys for the self-hosted version.

    git clone --recurse-submodules https://github.com/helldivers-2/api.git
    docker build -f ./src/Helldivers-2-API/Dockerfile -t helldivers2-api .
    docker run -p 8080:8080 helldivers2-api
  8. Identify your application using X-Super-Client headers

    master

    To help the community maintain the API and notify developers of breaking changes, you should include identification headers in your requests. While not currently mandatory, the X-Super-Client header will be made obligatory in the future.

    Required/Recommended Headers

    • X-Super-Client: The name of your application or domain (e.g., X-Super-Client: my-app-name).
    • X-Super-Contact: (Optional) A way to contact you if your site lacks visible contact information. This is used to notify you of API changes or potential abuse restrictions.
    GET /some-endpoint HTTP/1.1
    Host: api.helldivers2.dev
    X-Super-Client: my-awesome-app
    X-Super-Contact: dev@example.com
  9. Disable client header validation

    master

    By default, the API validates that all requests include the X-Super-Client and X-Super-Contact headers. If you receive a 400 error stating these headers are required, you can disable this validation.

    Environment Variable: Helldivers__API__ValidateClients (set to false to disable).

    JSON Config:

    {
      "Helldivers": {
        "API": {
          "ValidateClients": false
        }
      }
    }