You can use the http
or https
from Ode himself to make the call.
This example is using the Mailgun api:
const https = require('https');
const config = require('./config'); // Meu ficheiro de configuração
helpers.email = function (data, callback) {
if (data) {
// Payload
const payload = {
'from': config.mailGun.defaultEmail,
'to': data.email,
'subject': data.orderId,
'text': data.body
};
var stringPayload = queryString.stringify(data);
// Request options
const requestOptions = {
'protocol': 'https:',
'hostname': 'api.mailgun.net',
'path': `/v3/${config.mailGun.sandboxDomain}/messages`,
'method': 'POST',
'headers': {
'Authorization': `Basic ${Buffer.from(`api:${config.mailGun.apiKey}`).toString('base64')}`,
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(stringPayload)
}
}
//making a request
var req = https.request(requestOptions, res => {
var status = res.statusCode;
if (status == 200) {
callback(status);
debug(status);
} else {
callback(status);
}
});
req.on('data', (data) => {
callback(data);
});
req.on('error', (e) => {
console.log(e);
debug('Email failed to send');
});
//attaching the string payload
req.write(stringPayload);
//sending the request
req.end();
} else {
callback('missing required fields');
}
};
The same way you request a page in Apache, IIS, Tomcat... by URL.
– Oralista de Sistemas
For you to get started it’s good to see a tutorial: https://code4coders.wordpress.com/2016/10/14/development-uma-application-restful-api-em-node-js-express-js-com-mongodb/ It’s implemented from simple to what you want. As soon as you have any doubt post your code snippet.
– alxwca