FabioEnne FabioEnne - 11 days ago 8
HTTP Question

How can I correctly make this http request?

Recently I stumble across this SimplePush.io wich is perfect for a project of mine, so basically it works perfect via curl as stated on the website:

~ $ curl 'https://api.simplepush.io/send/HuxgBB/Wow/So easy'


or

~ $ curl --data 'key=HuxgBB&title=Wow&msg=So easy' https://api.simplepush.io/send


So i'm trying to use it in my server-side application on NodeJS but I tried many and many ways without success..

So I was wondering if anyone out there could help me out to acomplish this with a bit of code. Many thanks in advance

I'm not gonna post any code I made because are all wrong and I don't know where to start

Answer

Firstly, install the npm request module.

$ npm install request

Then in your node file:

var request = require('request');
request('https://api.simplepush.io/send/HuxgBB/Wow/So easy', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body);
  }
})