-
Notifications
You must be signed in to change notification settings - Fork 6
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
Rework part of the lib to be more versatile #31
Conversation
index.js
Outdated
//# withHeader :: String -> String -> Response a b -> Response a b | ||
//. | ||
//. Sets the value of a header on the Response. | ||
export const withHeader = key => value => cata ({ | ||
Respond: (headers, code, body) => Response.Respond ( | ||
code, | ||
{...headers, [key.toLowerCase ()]: value}, | ||
body, | ||
), | ||
Next: Response.Next, | ||
}); | ||
|
||
//# withoutHeader :: String -> Response a b -> Response a b | ||
//. | ||
//. Removes a header from the Response. | ||
export const withoutHeader = key => cata ({ | ||
Respond: (headers, code, body) => Response.Respond ( | ||
code, | ||
{...headers, [key.toLowerCase ()]: undefined}, | ||
body, | ||
), | ||
Next: Response.Next, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this PR, it was not possible to modify response headers through fluture-express
index.js
Outdated
//# withStatus :: Number -> Response a b -> Response a b | ||
//. | ||
//. Sets the status code of the Response. | ||
export const withStatus = code => cata ({ | ||
Respond: (headers, _, body) => Response.Respond (headers, code, body), | ||
Next: Response.Next, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allowing response status to be modified allows Response constructors to use default response codes, making the common use case a little less verbose, and the less common use case a little more verbose.
I might want to add convenient ways of adding to the Cookies header, and the Content-Type header. |
And possibly also |
I like this new approach.
I am curious about this one. Why would you do so? Are those headers special in any way? |
@dicearr See the new commit. The idea is to have this lib be a straight-up proxy for the various methods and convenience methods that Express gives users to modify the response. So this lib will concern itself more with Express' interface, and less with what an HTTP response means in general. |
Codecov Report
@@ Coverage Diff @@
## master #31 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 1 1
Lines 239 461 +222
==========================================
+ Hits 239 461 +222
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great.
It has taken me quite some time to wrap my head around the deriveEq
function but I couldn't come up with a simpler/more obvious approach.
This introduces some ideas that @voxbono and I worked out on Gitter a while ago. You might be interested @voxbono :)
The idea is that the constructors themselves don't take any headers or status code, but that they can be added via function calls afterwards: