node-js访问rest api的方法

//npm install node-rest-client --save-dev

var Client = require('node-rest-client').Client
function locate() {
    var client = new Client()
    var args = {
        data: { input: "hello" },
        headers: { "Content-Type": "application/json" }
    };

    // registering remote methods 
    client.registerMethod("postMethod", "http://192.168.1.122:8082/api/geo/domain", "POST");

    client.methods.postMethod(args, function (data, response) {
        // parsed response body as js object 
        console.log(data);
        // raw response 
        console.log(response);
    });
}
原文地址:https://www.cnblogs.com/mayidudu/p/5818305.html