Lightweight module to simplify integration of external apps with MTA:SA servers. Uses the standard HTTP call interface, which you can learn more about here.
npm install mtasa --save
Import the Client
class:
TypeScript:
import { Client } from "mtasa";
JavaScript:
const Client = require('mtasa').Client;
Then create a new client instance and use it to make some remote calls:
// Setup a new client for local server
const mta = new Client("127.0.0.1", 22005, "root", "pass");
// Perform calls using async/await:
(async () => {
try {
// Call some procedure
const result = await mta.resources.test_resource.testProcedure("some param");
// Call a procedure (the alternative verbose API)
const verboseCallResult = await mta.call("test_resource", "testProcedure", "some param", 1234);
} catch (err) {
console.error(`Ooops! Something went wrong ${err}`);
}
})()
// Without async/await, plain old Promises:
mta.resources.test_resource.testProcedure()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.error(`Ooops! Something went wrong ${err}`);
});
For more information on how to expose your MTA server APIs (like the testProcedure
function from test_resource
resource) over the web interface, refer to Resource Web Access wiki page.
The source code has inline documentation, which is also included in typings (.d.ts
) shipped with the module. This means that no matter if you write plain old JavaScript or TypeScript - as long as you use some decent editor with intellisense (like Visual Studio Code), you should get nice autocompletion and feedback with documentation. Just give it a try yourself - use one of the examples above, type new Client(
at the very end and hit CTRL + Shift + Space
if the popup didn't appear automatically already.
You can also jump straight into the source code of the library and unit tests.
This library is totally usable but is perhaps still lacking some features, hence the 0.1.x version. I consider it stable for my own needs. Feel free to report bugs or feature requests here. PRs welcome too.
MIT