Skip to content

Update ContentTypeParser.md#1157

Merged
mcollina merged 1 commit intofastify:masterfrom
cemremengu:patch-2
Sep 12, 2018
Merged

Update ContentTypeParser.md#1157
mcollina merged 1 commit intofastify:masterfrom
cemremengu:patch-2

Conversation

@cemremengu
Copy link
Copy Markdown
Contributor

Updated based on #534

Checklist

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

Comment thread docs/ContentTypeParser.md Outdated
});
}
```
});
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Comment thread docs/ContentTypeParser.md Outdated

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

```
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

js

Comment thread docs/ContentTypeParser.md Outdated
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

No problem, thank you!

Copy link
Copy Markdown
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
Copy Markdown

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.

4 participants