HapiJS Route Return Response From RequestHow to manage a redirect request after a jQuery Ajax callHow do I remove a property from a JavaScript object?Abort Ajax requests using jQueryevent.preventDefault() vs. return falseWhy does Google prepend while(1); to their JSON responses?How do I remove a particular element from an array in JavaScript?Why does ++[[]][+[]]+[+[]] return the string “10”?How do I return the response from an asynchronous call?How are parameters sent in an HTTP POST request?Request data to global variable
Feedback diagram
Why are sugars in whole fruits not digested the same way sugars in juice are?
How does Asimov's second law deal with contradictory orders from different people?
Derivative is just speed of change?
Python π = 1 + (1/2) + (1/3) + (1/4) - (1/5) + (1/6) + (1/7) + (1/8) + (1/9) - (1/10) ...1748 Euler
Does the problem of P vs NP come under the category of Operational Research?
How to trick a fairly simplistic kill-counter?
"Will flex for food". What does this phrase mean?
How to prevent a single-element caster from being useless against immune foes?
Gold Battle KoTH
IBM mainframe classic executable file formats
Should I put my name first or last in the team members list?
Is it moral to remove/hide certain parts of a photo, as a photographer?
Can machine learning learn a function like finding maximum from a list?
Is there anyway to harden soft braised carrots?
How to derive trigonometric Cartesian equation from parametric
The grades of the students in a class
Base Current vs Emitter Base voltage
Password management for kids - what's a good way to start?
Normally Closed Optoisolators
Adjective for when skills are not improving and I'm depressed about it
A game of red and black
Conflict between senior and junior members
"Fewer errors means better products" or "Fewer errors mean better products"?
HapiJS Route Return Response From Request
How to manage a redirect request after a jQuery Ajax callHow do I remove a property from a JavaScript object?Abort Ajax requests using jQueryevent.preventDefault() vs. return falseWhy does Google prepend while(1); to their JSON responses?How do I remove a particular element from an array in JavaScript?Why does ++[[]][+[]]+[+[]] return the string “10”?How do I return the response from an asynchronous call?How are parameters sent in an HTTP POST request?Request data to global variable
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am using the request module and am making a successful request. I get the response back but I can not figure out how to return this response back to my route to return to my client.
My route:
'use strict';
const displayBuild = require('../lib/display-build');
module.exports =
method: ['PUT', 'POST'],
path: '/displayBuild',
handler: function(request, h)
console.log('Displaying build config...');
console.log(request.payload)
try
displayBuild(request, h);
console.log("h:", h)
return 'success': 201
catch (err)
console.log(err);
return 'ERR': err
;
displayBuild function:
var request = require('request');
var URL = "url"
const displayBuild = function (req, res)
var options =
uri: URL,
method: 'POST',
headers:
"content-type": "application/json"
,
json: req.payload
;
request(options, function (error, response, body)
if (!error && response.statusCode == 200)
console.log('success')
else
console.log('ERROR:', error)
throw error
return body;
);
module.exports = displayBuild;
Obviously return body
is not enough.
I would like to return the body back to my route and return that back as the response to my client.
Thank you!!
javascript node.js ajax request hapijs
add a comment |
I am using the request module and am making a successful request. I get the response back but I can not figure out how to return this response back to my route to return to my client.
My route:
'use strict';
const displayBuild = require('../lib/display-build');
module.exports =
method: ['PUT', 'POST'],
path: '/displayBuild',
handler: function(request, h)
console.log('Displaying build config...');
console.log(request.payload)
try
displayBuild(request, h);
console.log("h:", h)
return 'success': 201
catch (err)
console.log(err);
return 'ERR': err
;
displayBuild function:
var request = require('request');
var URL = "url"
const displayBuild = function (req, res)
var options =
uri: URL,
method: 'POST',
headers:
"content-type": "application/json"
,
json: req.payload
;
request(options, function (error, response, body)
if (!error && response.statusCode == 200)
console.log('success')
else
console.log('ERROR:', error)
throw error
return body;
);
module.exports = displayBuild;
Obviously return body
is not enough.
I would like to return the body back to my route and return that back as the response to my client.
Thank you!!
javascript node.js ajax request hapijs
add a comment |
I am using the request module and am making a successful request. I get the response back but I can not figure out how to return this response back to my route to return to my client.
My route:
'use strict';
const displayBuild = require('../lib/display-build');
module.exports =
method: ['PUT', 'POST'],
path: '/displayBuild',
handler: function(request, h)
console.log('Displaying build config...');
console.log(request.payload)
try
displayBuild(request, h);
console.log("h:", h)
return 'success': 201
catch (err)
console.log(err);
return 'ERR': err
;
displayBuild function:
var request = require('request');
var URL = "url"
const displayBuild = function (req, res)
var options =
uri: URL,
method: 'POST',
headers:
"content-type": "application/json"
,
json: req.payload
;
request(options, function (error, response, body)
if (!error && response.statusCode == 200)
console.log('success')
else
console.log('ERROR:', error)
throw error
return body;
);
module.exports = displayBuild;
Obviously return body
is not enough.
I would like to return the body back to my route and return that back as the response to my client.
Thank you!!
javascript node.js ajax request hapijs
I am using the request module and am making a successful request. I get the response back but I can not figure out how to return this response back to my route to return to my client.
My route:
'use strict';
const displayBuild = require('../lib/display-build');
module.exports =
method: ['PUT', 'POST'],
path: '/displayBuild',
handler: function(request, h)
console.log('Displaying build config...');
console.log(request.payload)
try
displayBuild(request, h);
console.log("h:", h)
return 'success': 201
catch (err)
console.log(err);
return 'ERR': err
;
displayBuild function:
var request = require('request');
var URL = "url"
const displayBuild = function (req, res)
var options =
uri: URL,
method: 'POST',
headers:
"content-type": "application/json"
,
json: req.payload
;
request(options, function (error, response, body)
if (!error && response.statusCode == 200)
console.log('success')
else
console.log('ERROR:', error)
throw error
return body;
);
module.exports = displayBuild;
Obviously return body
is not enough.
I would like to return the body back to my route and return that back as the response to my client.
Thank you!!
javascript node.js ajax request hapijs
javascript node.js ajax request hapijs
asked Mar 26 at 23:40
DylanDylan
3145 silver badges17 bronze badges
3145 silver badges17 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I solved it myself by using async and await functionality. What I did was made the handler function an async function
async (request, h) =>
...
var body = await displayBuild(...)
and returned a new Promise from the displayBuild function.
Message me if anyone wants lower level explanation.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367727%2fhapijs-route-return-response-from-request%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I solved it myself by using async and await functionality. What I did was made the handler function an async function
async (request, h) =>
...
var body = await displayBuild(...)
and returned a new Promise from the displayBuild function.
Message me if anyone wants lower level explanation.
add a comment |
I solved it myself by using async and await functionality. What I did was made the handler function an async function
async (request, h) =>
...
var body = await displayBuild(...)
and returned a new Promise from the displayBuild function.
Message me if anyone wants lower level explanation.
add a comment |
I solved it myself by using async and await functionality. What I did was made the handler function an async function
async (request, h) =>
...
var body = await displayBuild(...)
and returned a new Promise from the displayBuild function.
Message me if anyone wants lower level explanation.
I solved it myself by using async and await functionality. What I did was made the handler function an async function
async (request, h) =>
...
var body = await displayBuild(...)
and returned a new Promise from the displayBuild function.
Message me if anyone wants lower level explanation.
answered Mar 27 at 1:29
DylanDylan
3145 silver badges17 bronze badges
3145 silver badges17 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367727%2fhapijs-route-return-response-from-request%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown