0.0.1 • Published 4 months ago
forgeapi v0.0.1
ForgeAPI
ForgeAPI, the best way to interact with your ForgeScript bot and it's server.
How to use
Download this npm package:
npm i forgeapi
Now, in your client initialization:
const { ForgeAPI } = require("forgeapi")
// I'll assume client, can be bot or anything else
const client = new ForgeClient({
...options // The options you currently have
extensions: [
new ForgeAPI({
port: number
authorization?: string | string[]
})
]
})
And voi-la, you now have ForgeAPI installed and loaded to your bot.
Note: if you add authorization you will have to assign in the headers
{
"authorization": "1 of the assigned keys you added"
}
Endpoints
Default
Endpoint | Method | Has WS |
---|---|---|
/usage | GET | yes |
/commands | GET | yes |
/guilds | GET | yes |
/{guild.id}/leave | POST | no |
Custom
Now, in your client initialization:
const { ForgeAPI } = require("forgeapi")
// I'll assume client, can be bot or anything else
const client = new ForgeClient({
...options // The options you currently have
extensions: [
new ForgeAPI({
port: number
load: string // Here add the path to load the custom endpoints
authorization?: string | string[]
})
]
})
On /<path>/<fileName>
add this
const data = {
url: '/endpoint',
method: "HTTP Method",
auth?: boolean,
handler: async function (ctx) {
ctx.reply.end('Endpoint here!');
},
wsHandler?: async funtion (ctx){
ctx.ws.send('WebSocket here!')
}
}
module.exports = { data }
Note: your const must always be named data.
More about RouteOptions: