Sunday, 15 June 2014

javascript - Invoke HTTP GET and POST request without pages using Node.js + Express -



javascript - Invoke HTTP GET and POST request without pages using Node.js + Express -

i have node.js app running expressjs. have typical setup right now, using view jade files , route js files process , post requests. illustration follows:

router.post('/postaction', function(req, res) { // elements actual jade view var 1 = req.body.from; var 2 = req.body.to; // }); router.get('/getaction', function(req, res) { // elements actual jade view var 1 = req.body.from; var 2 = req.body.to; // });

this works, can carry out , post requests. example, button might invoke post action. question is, how can utilize separate script or npm module invoke same , post requests without having via views? ideally, have this:

somescript-get <param1> somescript-post <param1> <param2>

with params beingness akin req.body.from , req.body.to. essentially, looking emulate info page without having utilize page itself.

i new node.js , appreciate help. please point out if haven't explained plenty , i'll seek to.

thank you

an often-used tool curl.

for instance, create get request:

$ curl 'http://your.url/getaction?from=foo&to=bar'

to create post request:

$ curl -xpost http://your.url/postaction -d 'from=foo&to=bar'

an alternative, 1 prefer myself, httpie.

javascript node.js post express get

No comments:

Post a Comment