nsapi is a free and open source library that allows Node.js applications to easily access the NationStates API without worrying about making HTTP requests, decoding XML, caching or rate limiting.
nsapi features the following:
You can install nsapi using npm: npm install nsapi
.
You can also build nsapi locally using npm: npm run-script build
.
Consult the documentation for more information on API structure and methods.
nsapi targets ES5 but requires support for ES6 promises, so if you're not using a runtime that supports them natively, you'll have to use a polyfill.
The following is a simple example that retrieves a nation's full name and prints it to the console.
var nsapi = require("nsapi");
// TODO: Replace the user agent with your own
var api = new nsapi.NsApi("Your nation's name");
return api.nationRequest("Auralia", ["fullname"])
.then(function(data) {
console.log(data["fullname"]);
})
.then(function() {
api.cleanup();
});
For additional examples, consult the examples/example.js file.
nsapi is licensed under the Apache License 2.0.
Generated using TypeDoc