kahmali / meteor-restivus

REST APIs for the Best of Us! - A Meteor 0.9+ package for building REST APIs https://atmospherejs.com/nimble/restivus
MIT License
544 stars 117 forks source link

Is it possible to read Content-type: text/plain data #293

Open cinderblock opened 6 years ago

cinderblock commented 6 years ago

Hello,

I've been searching around on this issue and haven't found a good answer. I hope I'm not doing something silly.

I have a simple program that periodically generates a block of text data and I need to pass that data to a meteor application and parse the weird text format there.

I'm using curl to send the data to my meteor server; something like: curl -d 'foo\nbar' -H 'Content-Type: text/plain' https://myserver/api/test. The problem is that in the request handler, this.bodyParams is always an empty object.

If other content types are used, restivus tries to parse the data but this doesn't always capture every byte. Notably, if Content-Type header is removed, curl defaults to application/x-www-form-urlencoded which is reversible for the simple example I provided, but not for other more complicated use cases.

Now, it is possible to get at the raw data with something like this: https://stackoverflow.com/questions/35857250/how-can-i-get-post-raw-body-in-meteor-restivus but that sure seems like a convoluted way to get the raw POST data. This is also not possible in my use case as the meteor app that I'm using doesn't expose the raw request object from restivus.

Would it be possible and make sense to add a text/plain parser?

cinderblock commented 6 years ago

I just noticed #108. Unfortunately the this.request._readableState.buffer.toString() method seems to not work for me. I'm running node v8.5.0. I've seen discussions around changing _readableState as it's supposed to be private. Maybe behavior has changed?

dkudrin commented 3 years ago

@cinderblock Hi! Sorry, have you found any solution? I'm struggling with the same issue.

cinderblock commented 3 years ago

Gosh, I don't even remember why I was using meteor for... Sorry.