50
loading...
This website collects cookies to deliver better user experience
# Install dependencies
$ npm install
# Start application
$ npm start
SendEmail
usecase to use circuit-breaker as failover policy.$ npx @superfaceai/cli install communication/send-email -i
superface
. It is a place where all configuration and metadata for OneSDK lives. Also, package.json
and package-lock.json
will be updated because CLI added @superfaceai/one-sdk
as a new dependency.routes/index.js
file.SuperfaceClient
from @superfaceai/one-sdk
packageconst { SuperfaceClient } = require('@superfaceai/one-sdk');
// Create OneSDK instance
const sdk = new SuperfaceClient();
// Load installed profile
const profile = await sdk.getProfile('communication/send-email');
// Use the profile to SendEmail
const to = req.body.to;
const result = await profile.getUseCase('SendEmail').perform({
to,
from: '[email protected]',
subject: 'Superface Resilient Email Tutorial',
text: `Hello ${to} from Superface Tutorial`,
});
// Get and show data
let data;
try {
data = result.unwrap();
} catch (error) {
console.error('Send Email Failed: ', error);
data = { error: 'Uups..' };
}
$ npm start
Send Hello
, you should get the message-id as result and receive the email./etc/hosts
. If you configured a different primary provider, use its respective API base URL./etc/hosts
with sudo$ sudo nano /etc/hosts
Password:
127.0.0.1 api.sendgrid.com
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 api.sendgrid.com
/etc/hosts
. It must be at least 30 seconds from failover to secondary, to get tried primary provider again.et