Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
95
rated 0 times [  96] [ 1]  / answers: 1 / hits: 16282  / 8 Years ago, fri, january 6, 2017, 12:00:00

I have a simple API route set up in Express (consumed mainly via my Angular frontend):



 app.post('/api/sendEmail', emailApi.sendEmail);


I've made a module that sits in my backend and also needs to call this service. I figured the easiest way was to do a POST request:



  request({
url: '/api/sendEmail',
method: 'POST',
json: {
template: template.toLowerCase(),
obj: mailObj
}
}, function(error, response, body){
console.log('error', error);
console.log('response', response);
console.log('body', body);
});


However, I get this error:



 Error: Invalid URI /api/sendEmail


What am I doing wrong here?


More From » node.js

 Answers
69

You need to use an absolute URI (including the protocol, domain, and port if it's not listening on the default port).



For example, if you know that the server will be listening at localhost:3000, you would want to replace your url value with 'http://localhost:3000/api/sendEmail'.


[#59443] Tuesday, January 3, 2017, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mari

Total Points: 305
Total Questions: 100
Total Answers: 98

Location: Somalia
Member since Mon, Feb 27, 2023
1 Year ago
;