title: Access the raw body of a request in koa.js
body: <p>I have created an API using <code>io.js</code> and <code>koa.js</code>. </p>
  
  <p>As a body parser middleware I am using <code>koa-body</code>, which in turn uses <code>co-body</code>.</p>
  
  <p>On one of my API endpoints I am receiving <code>POST</code> requests, and I need access to the raw body of the request, because I need to encode it to verify if the request is valid.</p>
  
  <p>Is there any way to access the raw body of the request? I tried to use the <code>raw-body</code> middleware, but if I use it before I call <code>koa-body</code>, the <code>co-body</code> used in <code>koa-body</code> breaks. If I use it after <code>koa-body</code> it does not work.</p>
  
  <pre><code>   app.use(function*(next){
      let rawRequestBody = yield rawBody(this.req);
      this.rawRequestBody = rawRequestBody;
  
      yield next;
    });
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I think that I found a workaround, but I don't know if this is the best solution. I think that @greim answer may be a better solution to this problem.</p>
  
  <p>I added the following code before I use <code>koa-body</code>:</p>
  
  <pre><code>app.use(function *(next) {
  
      let url = this.req.url;
  
      if(this.req.method == 'POST') {
        let that = this;
        this.req.rawBody = '';
  
        this.req.on('data', function(chunk) {
          that.req.rawBody += chunk;
        });
      }
  
      yield next;
    });
  </code></pre>