Skip to content

Is piping request streams possible? #534

@yamalight

Description

@yamalight

As I've figured it out with your help (thank you again for bearing with me 😄 ) in #492, one can accept streams using content type parser, i.e.:

fastify.addContentTypeParser('*', function (req, done) {
  var data = ''
  req.on('data', chunk => { data += chunk })
  req.on('end', () => {
    done(data)
  })
})

My question is - is it possible to pipe request stream into something? E.g. in express/hapi/micro/etc one can do something like this:

// init project
var express = require('express');
var app = express();

// http://expressjs.com/en/starter/basic-routing.html
app.post("/", function (request, response) {
  request.pipe(response);
});

// listen for requests :)
var listener = app.listen(process.env.PORT, function () {
  console.log('Your app is listening on port ' + listener.address().port);
});

And when sending POST request to / you'll get your body as a response.
Is it possible to do this with fastify? (not speaking about piping request to response, but rather piping request to other useful libs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationhelp wantedHelp the community by contributing to this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions