title: AWS SNS webservice subscription - express issue, sinatra example
body: <p>I'm simply trying to build an auto-subscription API which POSTs back the token. I can do this very easily in Sinatra (render the POSTed JSON from AWS) -- seem to be having a hard time in Express; I'm sure it's just something stupid I'm missing, though I've tried 1000X combinations.</p>
  
  <p>Here is the Sinatra webserver: </p>
  
  <pre><code># application.rb
  
  require 'rubygems'
  require 'sinatra'
  require 'json'
  
  set :port, 8081
  
  post '/webservice/cloudwatch' do
    content_type :json
    puts "Body: " + request.body.read
  end
  </code></pre>
  
  <p>Which logs:</p>
  
  <pre><code>- -&gt; /webservice/cloudwatch
  Body: {
    "Type" : "SubscriptionConfirmation",
    "MessageId" : "OMIT",
    "Token" : "OMIT",
    "TopicArn" : "OMIT",
    "Message" : "OMIT",
    "SubscribeURL" : "OMIT",
    "Timestamp" : "2012-02-28T21:28:02.082Z",
    "SignatureVersion" : "1",
    "Signature" : "OMIT",
    "SigningCertURL" : "OMIT"
  }
  </code></pre>
  
  <p>Here is the Express webserver:</p>
  
  <pre><code>var express, app, stache;
  express = require("express"), app = express.createServer();
  app.configure(function () {
    app.use(express.methodOverride());
    app.use(express.bodyParser());
    app.use(app.router);
    app.set("view options", {
      layout: false
    });
    app.use(express.errorHandler({
      dumpExceptions: true,
      showStack: true
    }));
  });
  app.post("/webservice/cloudwatch", function (request, response) {
    request.accepts('application/json');
    console.log("post body: " + JSON.stringify(request.params));
    console.log("post body: " + JSON.stringify(request.body.read));
  });  
  app.listen(8081);
  </code></pre>
  
  <p>Which logs:</p>
  
  <pre><code>post body: []
  post body: undefined
  </code></pre>
  
  <p>Please help!</p>