Simplify Node Http Response Logic
See original GitHub issueCurrently a http response exists in two forms:
context.res = bodyValue; // res is interpreted as 200 with body bodyValue
context.res = { body: bodyValue, headers: ..., status: ... } // res is fully specified object
Removing option 1 is something we ought to consider, as it has some negatives:
- We are forced to guess whether the returned object is a response based on existence of ‘body’ property, which in a couple cases is incorrect:
bodyValue
has abody
property (workaround is nested body inside body)- a response object is returned with only
headers
andstatus
- The ‘magic’ code of 1 doesn’t save lines of code
context.res = bodyValue; context.done();
vscontext.res.send(bodyValue);
- We would decrease the matrix of things we need to test (currently, different behavior in content type handling between 1 and 2)
- Simplified documentation and examples with a single recommended way of interacting with http in node
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Anatomy of an HTTP Transaction
Let's simplify the previous example to make a simple echo server, which just sends whatever data is received in the request right back...
Read more >node.js - How to limit content length response of simplified ...
I would like request() to stop downloading after 10MB. Usually, when request gets an answer it gets all the HTTP headers and everything...
Read more >Best Practices for Node.js Error-handling
This article will introduce you to error-handling in Node.js and demonstrate some of ... incorrectly applying the same logic everywhere to deal with...
Read more >Node JS Tutorial: The Basics
Whenever a new request is received, the request event is called, providing two objects: a request (an http.IncomingMessage object) and a response (an...
Read more >Node.js Error Handling Best Practices
It's a way to see bugs in your code. Following this logic, error handling is a way to find these bugs and solve...
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
@stefan-akelius At present all function triggers are routed through a C# process. We use edgejs for interop between node and C#. The requests are served in C# so unfortunately we don’t have access to a node generated
IncomingMessage
orServerResponse
(I’d love to support those types natively as well).figured this one out. 1.0 don’t like raw body content. can’t validate webhook that wanted text/plain response. argh.