Web Server 📮
Ratchet also runs a tiny internal web server to listen for HTTP requests.
Therefore, you can use it as a REST API to communicate with Ratchet.
Be it for controlling plugins or calling events.
By default, web server is accessible on: http://localhost:5460
Port can be changed in the configuration file.
WARNING
Make sure the web server's port is not publicly accessible from the internet, as that would allow malicious actors to disable your plugins remotely.
Plugin Management
/plugins GET API endpoint
Returns a JSON formatted list of all available plugins.
http://localhost:5460/plugins/reloadall GET API endpoint
http://localhost:5460/reloadall/reload GET API endpoint
http://localhost:5460/reload?plugin=myfirstplugin/unload GET API endpoint
http://localhost:5460/unload?plugin=myfirstplugin/watch GET API endpoint
http://localhost:5460/watch?plugin=myfirstplugin/refresh-schedule GET API endpoint
http://localhost:5460/refresh-schedule/refresh-plugins GET API endpoint
http://localhost:5460/refresh-pluginsDebugging
/debug GET API endpoint
Change the setting of debugFocus during runtime.
http://localhost:5460/debug/:focusFocus value can be empty to disable logging of hooks completely, or * to enable it for all (this is resource intensive and should be used sparsely).
Events
/event POST API endpoint
http://localhost:5460/eventExample:
curl -d "event=onTestEvent" -X POST http://localhost:5460/eventCustom API
You can create a file called restapi.lua in your root plugins folder to make use of built-in web server and create your own REST API that can communicate with your Ratchet plugins.
Functions will be called by their name and any output will be passed back to the caller as a JSON response. Restarts are not needed, the file is executed anew with every request.
WARNING
Do not declare any global variables in this file, as it may have unforeseen effects.
Example:
local Router = {}
function Router.Announcement(data)
local message = data.msg
if(message)then
TotChat.Broadcast(message)
return { status = "OK" }
end
return { status = "FAIL", reason = "No message provided" }
end
return Router/call POST API endpoint
http://localhost:5460/call/:functionAny parameters can be attached with this request and they will be present as a Lua table input in the callback function.
Example:
curl -d "msg=Hello world" -X POST http://localhost:5460/call/Announcement