# nlw-api A simple API that caches and allows you to fetch data from the [Non-Listworthy Extreme Demons spreadsheet](https://docs.google.com/spreadsheets/d/1YxUE2kkvhT2E6AjnkvTf-o8iu_shSLbuFkEFcZOvieA/edit) (and [Insane Demon Spreadsheet](https://docs.google.com/spreadsheets/d/15ehtAIpCR8s04qIb8zij9sTpUdGJbmAE_LDcfVA3tcU/edit)!) running on `https://nlw.oat.zone/`. Originally made for the [NLW Integration](https://geode-sdk.org/mods/oatmealine.nlw_integration/) Geode mod, but free for anyone to use. ## Documentation ### Endpoints #### `/list?type={type}` Fetches the entire list as a JSON, including levels of type `type`. `type` can be `regular`, `pending`, `platformer` or `all` and defaults to `regular`. **Returns**: An array of [`NLWLevel`](#nlwlevel--level)s. #### `/ids?type={type}` Fetches the IDS list as a JSON, including levels of type `type`. `type` can be `regular`, `platformer` or `all` and defaults to `regular`. **Experimental.** **Returns**: An array of [`IDSLevel`](#idslevel-level)s. ### Objects #### `Level` Represents a generic level. - `sheetIndex`: The row index of the level on the associated spreadsheet. 0-indexed. - `id`: The ID of the level, manifested from the sheet using dark magic. Can be `undefined` very rarely. - `name`: The name of the level. Standardized to the in-game level name. - `creator`: The creator(s) of the level, as listed on the sheet. - `description`: Descriptions and notes as listed on the sheet. #### `NLWLevel` : [`Level`](#level) Represents an NLW level. - `tier`: `"Fuck"`, `"Beginner"`, `"Easy"`, `"Medium"`, `"Hard"`, `"Very Hard"`, `"Insane"`, `"Extreme"`, `"Remorseless"`, `"Relentless"` or `"Terrifying"`. - `skillset`: Level skillset, as listed on the sheet. - `enjoyment`: Level enjoyment sampled from EDEL as a number, or `null`. - `broken`: If the level is broken in 2.2. `"no"`, `"slightly"`, `"very"`, `"absolutely destroyed"` or rarely `null` if unknown. #### `IDSLevel`: [`Level`](#level) Represents an IDS level. - `tier`: `"Fuck"`, `"Beginner"`, `"Easy"`, `"Medium"`, `"Hard"`, `"Very Hard"`, `"Insane"` or `"Extreme"`. - `skillset`: Level skillset, as listed on the sheet. - `broken`: If the level is broken in 2.2. `"no"`, `"yes"`, or rarely `null` if unknown. ### Self-hosting You can self-host the API yourself, if you so wish! Here's the rough steps: 1. Grab yourself a Google Sheets API key. This may sound extremely intimidating, but you can create a read-only Sheets API key with not much hassle with [this guide](https://theoephraim.github.io/node-google-spreadsheet/#/guides/authentication?id=api-key). 2. Install, either with NPM or Nix: 1. With NPM, run: ```sh npm install ``` Then, you can start it with: ```sh API_KEY=... node index.js ``` **However**, take note of the [environment variables](#environment-variables) available to use. 2. Use Nix to either just plainly run it: ```sh API_KEY=... nix run git+https://git.oat.zone/oat/nlw-api ``` Or import it into your system flake like so: ```nix nlw-api.url = "git+https://git.oat.zone/oat/nlw-api"; # in your `nixosConfiguration`: imports = [ inputs.nlw-api.nixosModules.nlw-api ]; ``` Afterwards, you can use it as a regular NixOS service: ```nix services.nlw-api = { enable = true; domain = "nlw.oat.zone"; apiKey = builtins.readFile /etc/sheets-api-key; port = 1995; }; ``` 3. You're done! It will take a while to fetch every level and their IDs initially, but in time you will have yourself the caches set up and the server up and running. ### Environment variables You can pass these into the server as config (an `.env` file will **not** work): - `API_KEY`: A Google API key - see [this guide](https://theoephraim.github.io/node-google-spreadsheet/#/guides/authentication?id=api-key) to see how to get one hassle-free - `PORT`: The HTTP port to host the server on - `CACHE_DIR`: The directory to store cached data in, defaults to `./cache/`