Search code examples
javascriptnode.jshttpcurl

How can I correctly make this http request?


Recently I stumbled across this SimplePush.io which is perfect for a project of mine, so basically it works perfectly 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 accomplish this with a bit of code. Many thanks in advance

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


Solution

  • 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);
      }
    })