A RESTful API framwork based on restify.
MTAPI privides a convenient way to build a pure API server.
You can just modify server_conf.js
to define your custom API, and then to code solveing function, the framwork will automatic deploy solveing function to API request.
git clone git@github.com:tfh93121/node-mt-api.git
or
https://github.com/tfh93121/node-mt-api.git
then
npm install
module.exports = {
Test: { //class
hello: { //func
params: ["name", "msg"],
methods: ["post", "get"],
},
},
}
3. In API floder, create a file named Test.js
, attention the file name must be equal to classname in server_conf.js
just defined.
4. Edit Test.js
, create a function named hello
, it's equals to function name just defined in server_conf.js
.
just like:
//Test class
/**
* Hello world
*/
function hello(req, res, next) {
//the params like req res next must be defined.
let data = {
ret: 200,
msg: req.params.msg,
name: req.params.name,
}
res.send(data);
next();
}
module.exports = {
hello,
}
The result will be like:
Start deploy API...
Deploy completed!
MTAPI server listening at http://[::]:8080