title: /post request containing data using request.payload (hapi.js)
body: <p>I'm trying to do a /post request to my server that gives data (saves to db (knex)) using Hapi.js.</p>
  
  <p>Along with the post request, i'm trying to use 2 functions that will turn a random number into a hex string and set it to the hexString key in my data object.</p>
  
  <p><strong><em>routes.js</em></strong></p>
  
  <pre><code>module.exports.postData = {
    method: 'POST',
    path: '/',
    handler: (request, reply) =&gt; {
      const post = request.payload
      const data = {
        id: uuid.v4(),
        timeOut: null,
        uri: post.uri,
        payload: post.payload,
        hexString: undefined
      }
      store.link.createRandomInt()
        .then((randomNum) =&gt; {
          store.link.createHexString(randomNum)
            .then((hex) =&gt; {
              data.hexString = hex
              reply(store.link.createLink(data)).code(201)
            })
        })
     }
  }
  </code></pre>
  
  <p><strong><em>functions.js</em></strong></p>
  
  <pre><code>module.exports.createRandomInt = function () {
    return new Promise(function (resolve, reject) {
      var randomNumber = Math.floor((Math.random() * 100000000))
      resolve(randomNumber)
    })
  }
  
  module.exports.createHexString = function (int) {
    return new Promise(function (resolve, reject) {
      var hexString = int.toString(32)
      resolve(hexString)
    })
  }
  </code></pre>
  
  <p><strong><em>dbFunctions.js</em></strong></p>
  
  <pre><code>module.exports = {
    createLink: function (link) {
      return db('links').insert(link)
        .then((id) =&gt; {
          return {
            id: uuid.v4(),
            timeOut: null,
            uri: link.uri,
            payload: link.payload,
            hexString: link.hexString
          }
        })
     }
  }
  </code></pre>
  
  <p><strong><em>Post Curl Command:</em></strong></p>
  
  <pre><code>curl http://localhost:8000/ -d "uri: 'this is the uri' payload: { jsonObj: 'enter payload info here'}"
  </code></pre>
  
  <p><strong><em>What Post Curl Command Returns:</em></strong></p>
  
  <pre><code>{"id":"87c467dd-3703-4f9f-a1ac-78551dc33109","timeOut":null}
  </code></pre>
  
  <p><strong><em>When I console.log() the returned data object:</em></strong></p>
  
  <pre><code>Promise {
    _bitField: 0,
    _fulfillmentHandler0: undefined,
    _rejectionHandler0: undefined,
    _promise0: undefined,
    _receiver0: undefined }
  </code></pre>
  
  <p>Thanks for any input~</p>