Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ContentTypeParser.md #1157

Merged
merged 1 commit into from
Sep 12, 2018
Merged

Update ContentTypeParser.md #1157

merged 1 commit into from
Sep 12, 2018

Conversation

cemremengu
Copy link
Contributor

Updated based on #534

Checklist

  • documentation is changed or added
  • commit message and code follows Code of conduct

});
}
```
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example may be wrong: in fact you can use https://www.fastify.io/docs/latest/ContentTypeParser/#body-parser directly. Maybe we can add and example to parse a json line:

const split2 = require('split2')

  fastify.addContentTypeParser('*', (req, done) => {
    done(null, pump(req, split2(JSON.parse)));
  });

	fastify.route({
    method: 'POST',
    url: '/api/log/jsons',
    handler: (req, res) => {
        var data = [];
        req.body.on('data', d => console.log(d)) // log every incoming object
    }
});

or something like that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should provide an upload example since I feel like most people will be looking for things like uploading files to S3 so it can directly provide them the answer but it is up to you.

Maybe we can fix that example using the approach you provided?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is actually this plugin for upload so I guess we can give a reference there for upload


and then access the core HTTP request directly for piping it where you want:

```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

js

docs/ContentTypeParser.md Outdated Show resolved Hide resolved
Copy link
Member

@allevo allevo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm 👍 for adding those kind of changes!

Many thanks!

Only a few nits

@cemremengu
Copy link
Contributor Author

No problem, thank you!

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mcollina mcollina merged commit d0d2aa9 into fastify:master Sep 12, 2018
@delvedor delvedor added the documentation Improvements or additions to documentation label Sep 24, 2018
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants