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;








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!!










share|improve this question






























    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!!










    share|improve this question


























      0












      0








      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!!










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 26 at 23:40









      DylanDylan

      3145 silver badges17 bronze badges




      3145 silver badges17 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          0














          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.






          share|improve this answer
























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



            );













            draft saved

            draft discarded


















            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









            0














            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.






            share|improve this answer





























              0














              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.






              share|improve this answer



























                0












                0








                0







                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.






                share|improve this answer













                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 27 at 1:29









                DylanDylan

                3145 silver badges17 bronze badges




                3145 silver badges17 bronze badges





















                    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.



















                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현