title: Koajs how to send a json response
body: <p>I have this bit of code:</p>
  
  <pre><code>router.post('/register', function *(next) {
    User.create(this.request.body, function(err, data) {
      this.type = 'json';
      if (err) {
        return this.body = err;
      }
      return this.body = data;
    });
  });
  </code></pre>
  
  <p>But I get a 404 error (I'm assuming it's because the <code>router.post</code> returns instantly and doesn't wait for the callback. How can I yield a response from the inside of the callback so that I don't get a 404.</p>