Last active
December 20, 2015 20:39
-
-
Save TobyEalden/6192116 to your computer and use it in GitHub Desktop.
POST to API implemented using express
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require("express"); | |
var app = express(); | |
app.use(express.bodyParser()); | |
app.post('/postTest', function(req, res) { | |
if (req.body.hasOwnProperty("test")) { | |
console.log("test property is: " + req.body.test); | |
res.json({ok: true }); | |
} else { | |
console.log("no test property"); | |
res.json({ok: false }); | |
} | |
}); | |
app.listen(5000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var restClient = require("node-rest-client").Client; | |
var appgAPIClient = new restClient(); | |
var apiURLBase = "http://localhost:5000"; | |
var args = { | |
data: { test: "hello" }, | |
headers: {} | |
}; | |
appgAPIClient.post(apiURLBase + "/postTest", args, function(data,response) { | |
if (data.hasOwnProperty("ok") && data.ok === true) { | |
console.log("success"); | |
} else { | |
console.log("failure"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment