1.1.1 • Published 5 years ago

dnd5e-server v1.1.1

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

DnD5e TypeScript APi (server edition)

This repo offers typings and function endpoints to the DnD 5e API. It is based on the dnd5e package and can be used with the dnd5e-client package.

installation

Yarn

yarn add dnd5e-server

NPM

npm install dnd5e-server

use

After installing you can import normally:

import * as DnD from "dnd5e-server";

// -- or --

import {AbilityScore} from "dnd5e-server";

access endpoints directly

From a Node server, you can directly access the DnD 5e API through the ServerEndpoints module.

import * as DnD from "dnd5e-server";

DnD.ServerEndpoints.skills()
	.then(console.log);

Every endpoint in ServerEndpoints returns a promise that resolves to a JSON object (typed). If you're only intending to access the API directly like this you do not need the middleware or dnd5e-client package For more information on individual endpoints, see the JSDocs, or the DnD 5e API docs.

using the middleware

If you would like to pass the client direct access to the API, use the included Express middleware.

import { Server } from "http";
import * as DnD from "dnd5e-server";

const app = express();
const server: Server = require("http").Server(app);

app.use(DnD.middleware);

server.listen(3000);

You can now make calls to from the client to /dnd5e/{endpoint} (see DnD 5e API docs for a full list of endpoints).

fetch("/dnd5e/skills")
	.then(console.log);

Alternatively, once you have the middleware set up, you can use the dnd5e-client package, which comes with all the functions and typings for the client.

1.1.1

5 years ago

1.1.0

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago