body-parser icon indicating copy to clipboard operation
body-parser copied to clipboard

build-your-own-parser

Open dougwilson opened this issue 11 years ago • 19 comments

If you look at the middleware, after I had refactored it, all they are is a call to typeis and a call to read. We should add something like bodyParser.generic() to let people roll their owner simple body parsers.

dougwilson avatar May 27 '14 20:05 dougwilson

I think this lib is pretty easy to understand. IMO they should just fork this lib if they wanna do more stuff. Most of the logic should be in separate libs anyways

jonathanong avatar May 27 '14 21:05 jonathanong

I think it would be better to have the interface and people have parsing libs than lots of body-parser forks.

Fishrock123 avatar May 27 '14 21:05 Fishrock123

I think it would be better to have the interface

This module should be the interface. json and urlencoded should be the separable libs that use this module ;)

dougwilson avatar May 27 '14 21:05 dougwilson

You guys are just adding more responsibility to your plate hah

jonathanong avatar May 28 '14 00:05 jonathanong

Yeah, that's the issue, may be too much to be worthwhile to support.

Fishrock123 avatar May 28 '14 00:05 Fishrock123

i.am.machine :DDD

dougwilson avatar May 28 '14 00:05 dougwilson

This module should be the interface. json and urlencoded should be the separable libs that use this module ;)

I can tackle this if it's helpful

mikermcneil avatar Jul 29 '14 22:07 mikermcneil

This is actually nearly done, as it was intended for the goal of bringing body-parser back into express core.

Out of curiosity, what parser were you planning to build that we don't have already :)?

dougwilson avatar Jul 29 '14 22:07 dougwilson

Out of curiosity, what parser were you planning to build that we don't have already :)?

good question

mikermcneil avatar Jul 29 '14 23:07 mikermcneil

xml

mikermcneil avatar Jul 29 '14 23:07 mikermcneil

lol

mikermcneil avatar Jul 29 '14 23:07 mikermcneil

xml

lol. Somehow I knew that was the answer ;) Currently the best you can do is to use bodyParser.text and then feed the text into a XML parser.

dougwilson avatar Jul 29 '14 23:07 dougwilson

The reason why I had a feeling is because I use this module to parse XML all the time, but of course using text + parser requires the request body to buffer up instead of feeding it to an incremental parser (CSV is another common one, which I also use!).

This new stuff will actually be out sooner rather than later since I should not be distracted with express core.

dougwilson avatar Jul 29 '14 23:07 dougwilson

Out of curiosity, what parser were you planning to build that we don't have already :)?

JSON5? I use that in a few APIs, because it's easier to debug such api with a curl (and b/w compatibility with json is perfect). Even created express-json5 based on bodyParser.

So this use-case is more real than it seems.

rlidwka avatar Aug 01 '14 18:08 rlidwka

Even created express-json5 based on bodyParser.

Though it looks like as body-parser is currently, it can be significantly simplified by wrapping bodyParser.text ;)

dougwilson avatar Aug 01 '14 19:08 dougwilson

@rlidwka or, looking at your code now, you could technically wrap bodyParser.json and if it errors, check err.body and parse that with the json5 parser :) I'm not actually saying this invalids the issue at had, here, because it's still valid and I'm working on it, haha.

dougwilson avatar Aug 01 '14 21:08 dougwilson

How do you build may I ask?

lopugit avatar Jun 12 '19 02:06 lopugit