guildwars2-ts
Version:
GuildWars 2 API Wrapper in Typescript
67 lines (49 loc) • 2.75 kB
Markdown
[![NPM version][npm-image]][npm-link]
[![License][license]][license-file]
This project is a third-party package, and is strictly not affiliated with GuildWars2, ArenaNet, or NCSoft.
When used, no data is saved by, or sent to the developers, including but not limited to the logs, api tokens, or any objects returned by the endpoints.
Full support of all endpoints listed in the [API:2 Wiki](https://wiki.guildwars2.com/wiki/API:2) page
```typescript
import { GW2Api, ApiLanguage, setLogLevel, LogLevel } from "guildwars2-ts";
const api: GW2Api = new GW2Api({
// Some endpoints require authentication
token: "YOUR-TOKEN-HERE",
language: ApiLanguage.English,
// Optional, but recommended
rateLimitRetry: true
// When using guildwars2-ts in a browser, setting this is required to avoid CORS errors. Can be omitted otherwise
inBrowser: true
});
// Set to error by default, so you can set it to info for extra verbosity
setLogLevel(LogLevel.info);
// Set to true by default, but recommended to be turned off, if your log does not render correctly
enableLogColors(false);
(async () => {
// Obtain names of all characters on the account
await api.account.get().then(console.log);
// Obtain details about each of them
await api.characters.get().then((characters) => {
characters.forEach(async (character) => {
await api.characters.getCore(character).then(console.log);
});
});
// Types are automatically inferred for any function calls, like shown above
// If explicit types are preferred, it can be done as well
// Zod@^4 is required for this. In the future, this will be simplified
const emblems: z.infer<typeof EmblemDTO> = await api.emblem.get("foregrounds", [1, 2, 3]);
})();
```
If you encounter any kinds of errors, or wish to add/update the functionality provided by this project, please feel free to open a pull request against the [development branch](https://gitlab.com/dinckelman/guildwars2-ts/-/tree/dev).
Otherwise, please check open [issue reports](https://gitlab.com/dinckelman/guildwars2-ts/-/issues/), to see if there is an existing discussion on the issue, or open a new request. In case of runtime errors, request validation error logs are extremely helpful, so please include them in the report, as guided by the template.
* Request caching (under consideration)
* Support for pagination
* Support for different/older schema version
[npm-image]: https://img.shields.io/npm/v/guildwars2-ts
[npm-link]: https://www.npmjs.com/package/guildwars2-ts
[license]: https://img.shields.io/gitlab/license/dinckelman%2Fguildwars2-ts
[license-file]: LICENSE