Skip to content

jakobkg/startgg-api-proxy

Repository files navigation

Contributors Issues MIT License


Logo

Start.gg API proxy

A start.gg API proxy to help keep your API keys safe

About

When working with an API such as start.gg's GraphQL API, managing your API key and making sure not to accidentally reveal it by packaging it with your application or sending it in plain text over the network from your users' computers is of great importance. This project aims to create an API proxy that stores your API key and takes care of communicating with the start.gg API without your API key ever touching your users' computers or networks.

(back to top)

Getting Started

To get your own copy of this proxy running, you will need a Cloudflare account to create a Worker on, and a start.gg account to get an API key from

Prerequisites

Node/NPM

Install Node using the instructions on their website, either a binary install or using your package manager of choice.

Wrangler

Wrangler is the command line tool used to manage Cloudflare Workers. Install it using your package manager of choice, or from npm using

npm install wrangler -g

Once installed, connect Wrangler to your Cloudflare account using

wrangler login

Installation

  1. Clone the repo
    git clone https://github.com/jakobkg/startgg-api-proxy.git
    
    cd startgg-api-proxy
  2. Get your Cloudflare account ID by running
    wrangler whoami
    Then add the account ID to wrangler.toml
    account_id = "YOUR ID GOES HERE"
  3. Get your start.gg API key from your start.gg profile settings, then add this API key to the Worker with
    wrangler secret put STARTGG_API_KEY
  4. Install dependencies (typescript and webpack for building, prettier for code formatting)
    npm install
  5. All done! You can now run the proxy in a dev environment with
    wrangler dev
    or publish the proxy to your Cloudflare Workers with
    wrangler publish

(back to top)

Usage

This proxy expects to receive a POST request with a body

{
  groupId: number
}

The groupId is used in a query to the start.gg GraphQL API, the exact query can be found in the query.ts source file. The response to this query is directly forwarded as a response to the original POST request.

The shape of the response from the start.gg API is consistent and can be consumed into a relatively simple object.

Typescript example

declare type PhaseResponse = {
  data: {
    phase?: Phase;
  },
  extensions: {
    cacheControl: {
      version: number;
      hints?: Array<{
        path: Array<string>;
        maxAge: number;
        scope: string;
      }>
    }
    queryComplexity: number;
  },
  actionRecords: Array<{}>; // I have not been able to find documentation on this field,
                            // but have also never seen it populated
}

declare type Phase = {
  name: string;
  sets: {
    nodes: Array<{
      fullRoundText: string;
      round: number;
      slots: Array<{
        entrant: {
          name: string;
        },
        standing: {
          stats: {
            score: {
              value: number;
            }
          }
        }
      }>
    }>
  }
}

For concrete response examples, please refer to the start.gg API explorer and schema reference

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Attributions

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published