Body parsing
See original GitHub issueHow does this work with spirit? It’s a really important part of any webserver.
Would be nice to have an example in the guide an possibly even an included parser in spirit (like ['ip', 'headers']
).
Any help is appreciated, even if it’s just telling me where I can find the information needed to assemble the body myself.
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Understanding Body Parser In Express JS - Simplilearn
Body -parser parses is an HTTP request body that usually helps when you need to know more than just the URL being hit....
Read more >body-parser - npm
Node.js body parsing middleware. Parse incoming request bodies in a middleware before your handlers, available under the req.body property.
Read more >Body-parser middleware in Node.js - GeeksforGeeks
Body -parser is the Node.js body parsing middleware. It is responsible for parsing the incoming request bodies in a middleware before you ...
Read more >What is Express body-parser? - Educative.io
Express body-parser is an npm library used to process data sent through an HTTP request body. It exposes four express middlewares for parsing...
Read more >How to use body parser in express for handling POST requests
Body parser when used inside Express allows you to easily parse the body for different Content-Types in POST requests coming from tag, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I spoke to @dodekeract in gitter, to recap some main points from there:
I know most of this discussion comes from the article I wrote about spirit performance.
Good fundamentals, not micro optimizing
The article was about how structural changes / implementation as a whole can affect performance. And as along as you come into designing something with good fundamentals, you get good results (ie: never wrote spirit to be fast, it just happened that way).
Remember not every request has a request body.
‘Native’ vs using spirit-express
A ‘native’ body parser would be nice (it is on my list of todos). The performance difference between using spirit-express and it just being native is really small. Any performance benefit comes from rewriting the core functionality from whatever express middleware, and not so much from not having to use spirit-express.
My issue with spirit-express was never the performance, that’s why I quote the word “native”. That word in general makes it sound much faster haha. But my issue was you lose out on the benefits of spirit, (testability, thinking about a request / response as being transformed vs changes being crammed onto a req / res object).
Middleware is slow anyway
Using middleware in express or spirit or anything else will take a hit in performance regardless of what the middleware does. Reason usually varies for that project. For spirit, it’s because of Promises (or enforcing use of Promise). Remember also in spirit middlewares return, they rewind back vs callback based of only ‘going forward’.
Is middleware use slower than express?
No, it’s still faster.
I got a lot of comments for my article about why I didn’t test using middleware / logic. And I didn’t understand the point of it.
If I tested spirit and express and had the test both use the “body-parser” module, what’s the point of it? The body-parser performance is relative to itself and not to spirit or express. So if spirit is faster than express, using body-parser, passport, or whatever else, you would see the same results.
Informal Benchmarks
Informal meaning I just put it together real fast to show my point:
Every request is a POST with a small body.
spirit + body-parser via spirit-express:
express + body-parser:
Results
Both spirit and express take a big hit when you use a middleware (body-parser in this case). Is it because of body-parser ? Yea because it’s not a cheap operation, but also you have to pay a price for just using middleware in general.
This ended up being long haha, maybe I’ll convert it into a follow up article / post. Also I do think the body-parser can and should be re-written. I think the performance difference would be minor (when compared to the grand scheme of things), but still worth the effort as it’s a small project.
Closing in favor of
dodekeract/spirit-body
.