A wrapper for the RHostMush HTTP API, and a curl operation to use it's Header only schema.
MIT
npm i @digibear/rhost-wrapper
const { API } = require("@digibear/rhost-wrapper");
const api = new API({
user: "#123",
password: "xxxxxxxxxx",
port: 2222,
encode: true, // On by default to fix an stunnel bug.
});
get(command: string [, options: curlOptions])
.get allows you to send commands to the game, and recieve feedback through the API connection.post(command: string [, options: curlOptions])
.post allows you to affect the game by sending commands. Any command sent@emit
for example, will be evaluated by the API object and issued to the game.
- GET
Exec
Parse
- parse
- noparse
- ansiparse
- ansinoparse
- ansionly
Encode
- yes
- no
- PUT
Exec
time
- number
Traditional Promises
api
.get("WHO")
.then((res) => {
if (res.ok) {
console.log(res.data);
} else {
console.error(`API ERROR: ${res.message}`);
}
})
.catch((err) => console.error(err));
Async/await
const async getWHO = () => {
const res = await api.get('WHO');
res.ok
? console.log(res.data)
: console.log(`API ERROR: ${res.message}`);
}
// call the function and catch any errors.
getWHO().catch(err => console.error(err))
API support for conditional get post headers.For help setting up your Rhost API object, seewizhelp api
andwizhelp @api
.
Enjoy!