imrefazekas / connect-rest

Exceptionally featureful Restful web services middleware for connect node.js
MIT License
100 stars 29 forks source link

Parameters are not getting populated #11

Closed behrangsa closed 10 years ago

behrangsa commented 10 years ago

When a request comes to /api/event-log.csv?d=13&m=1&y=2014, parameters and params remain empty:

{ headers:
   { host: 'localhost:8080',
     connection: 'keep-alive',
     accept: 'application/json, text/plain, */*',
     'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTM
L, like Gecko) Chrome/31.0.1650.63 Safari/537.36',
     referer: 'http://localhost:8080/',
     'accept-encoding': 'gzip,deflate,sdch',
     'accept-language': 'en-US,en;q=0.8',
     httpVersion: '1.1',
     method: 'GET',
     originalUrl: '/api/event-log.csv?d=13&m=1&y=2014',
     clientAddress: '127.0.0.1' },
  parameters: {},
  params: {},
  files: undefined,
  session: undefined }

Here's the code that's causing this:

restSupport.get({ path: '/event-log.csv'}, function (req, content, next) {
      console.log(req);
      var response = grunt.file.read("api/event-log.csv");
      next(null, response);
   }, {contentType: 'application/csv'});
imrefazekas commented 10 years ago

For me it works:

{ headers: 
     { 'user-agent': 'curl/7.30.0',
         host: 'localhost:8080',
         accept: 'application/json',
         'content-type': 'application/json',
         httpVersion: '1.1',
         method: 'GET',
         originalUrl: '/api/event-log.csv?d=13',
         clientAddress: '127.0.0.1' },
    parameters: { d: '13' },
    params: { d: '13' },
    files: undefined,
    session: 
     { cookie: 
            { path: '/',
                _expires: null,
                originalMaxAge: null,
                httpOnly: false } } }

Maybe you are not using the connect layer properly. Connect does not care about request parameters directly, but connect middle wares do:

.use( connect.query() )
.use( connect.cookieParser() )
...
.use( connect.urlencoded() )
.use( connect.json() )

Please, check your connect set-up.