title: CypressIO make a request then use the response to pass to another function to call another request, wrap inside a re-usable function
body: <p>So the issue i have is i want to be able to call a module function, that will then call cy.request() get the response and feed this to another cy.request() in a nice way.</p>
  <p>I want to make this code nicer:</p>
  <pre><code>Cypress.Commands.add('createUser', (user) =&gt; {
    cy.request({
    method: 'POST',
    url: 'https://www.example.com/tokens',
    body: {
      email: 'admin_username',
      password: 'admin_password'
   }
  }).then((resp) =&gt; {
     cy.request({
       method: 'POST',
       url: 'https://www.example.com/users',
       headers: ({ Authorization: 'Bearer ' + resp.body.token }),
       body: user
    })
  })
  })
  </code></pre>
  <p>I'd like to to have the two cy.requests within their own functions, e.g getAuthToken() and createUser(), so i can wrap that in either a Cypress.Command, or just a module function and call within the test file</p>
  <pre><code>const seedUser = (userObject) =&gt; {
               getAuthToken().then((token) =&gt; {
                   return createUser(token); //where this would return the created user.
               }       
           }
  </code></pre>
  <p>then used like so in the test file</p>
  <pre><code>before(()=&gt;{
      let user =  seedUser();
   //or
   let user = cy.seedUser();
  }
  </code></pre>