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
[WIP] 🔥 Feature!: Add Req and Res API #2894
base: main
Are you sure you want to change the base?
Conversation
Important Auto Review SkippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
client.go
Outdated
@@ -19,14 +19,16 @@ import ( | |||
"github.com/valyala/fasthttp" | |||
) | |||
|
|||
// XXX TODO FIXME had to comment out the below types |
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.
I wouldnt worry about client.go until #1986 is merged
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.
@nickajacks1 Now its merge, you might need to fix the merge conflcits to be able to pull all the recent changes to main
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2894 +/- ##
=======================================
Coverage ? 82.98%
=======================================
Files ? 118
Lines ? 8541
Branches ? 0
=======================================
Hits ? 7088
Misses ? 1116
Partials ? 337
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@nickajacks1 Just so you are aware, the tests are very unstable/flaky right now in |
3/9: Moved some more methods from Ctx to Request. Rebased. |
3/17: Rebase. Moved more trivial methods to Request. |
Hi @gofiber/maintainers Sorry this is taking so long. |
Even though Express has Locals as part of the res API, I feel like it makes more sense to keep it as part of Ctx since it doesn't inherently have anything to do with the response (or request for that matter). I'm going to leave in Ctx for now. |
ok, sounds reasonable we can always adapt it later |
2a82670
to
31fde6b
Compare
Ok, the Response API is fully moved over. Some remaining work: Next week I'll start on either the docs or the interface part. |
CURRENT STATUS
Change ctx.Response to return a new fiber.Response object. Minimal changes required to get things to build.
TODO
Description
Split the existing Ctx API into two separate APIs for Requests and Responses. Having distinct APIs for Request and Response types will allow developers to more easily write self-documenting code by avoiding ambiguous methods such as
Ctx.Cookie
andCtx.Cookies
. Much of the existing Ctx API simply calls the corresponding Req or Res API. For example,Ctx.Get
callsRequest.Get
andCtx.Set
callsResponse.Set
.Because Express defines only res and req APIs with no context API, this change will make it easier to manage Fiber's adherence to Express's APIs. In addition, it will allow us to avoid needing to create certain one-off methods. For example,
Ctx.GetRespHeader
can now becomeCtx.Res().Get
Although the majority of the Ctx API is unchanged,
Ctx.Request
andCtx.Response
have been removed in favor ofCtx.Req
andCtx.Res
. Now, instead of a rawfasthttp.Request
orfasthttp.Response
, we returnfiber.Request
andfiber.Response
objects, which implement their respective APIs. As such, this is a breaking change for users who accessCtx.Request
andCtx.Response
direct.Inspired by Koa and fasthttp, both of which have individual request/response objects and a single context object whose methods are simply aliases for corresponding methods on the req/res APIs.
Deprecation:
Ctx.GetRespHeader
is replaced byCtx.Res().Get
Related to #2854
Changes introduced
List the new features or adjustments introduced in this pull request. Provide details on benchmarks, documentation updates, changelog entries, and if applicable, the migration guide.
Type of change
Please delete options that are not relevant.
Checklist
Before you submit your pull request, please make sure you meet these requirements:
/docs/
directory for Fiber's documentation.