Skip to content

docs: clarify handler parameters and execution order in routing methods#3512

Closed
sixcolors wants to merge 2 commits into
mainfrom
docs-handler-execution-order
Closed

docs: clarify handler parameters and execution order in routing methods#3512
sixcolors wants to merge 2 commits into
mainfrom
docs-handler-execution-order

Conversation

@sixcolors
Copy link
Copy Markdown
Member

Enhance documentation to explicitly define the required main handler and optional additional handlers in routing methods. This change improves clarity and type safety by clearly outlining the execution order of handlers.

Copilot AI review requested due to automatic review settings June 9, 2025 16:21
@sixcolors sixcolors requested a review from a team as a code owner June 9, 2025 16:21
@sixcolors sixcolors requested review from ReneWerner87, efectn and gaby June 9, 2025 16:21
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 9, 2025

Walkthrough

The changes update documentation comments and examples for HTTP method registration functions and related documentation files. They clarify the execution order of route handlers, specify the main handler as a required parameter, and illustrate the updated method signatures, including the use of a slice for multiple HTTP methods in the Add function. No functional code changes are introduced.

Changes

Files / Groups Change Summary
app.go Added detailed documentation comments to all HTTP method registration functions and examples showing handler order.
docs/partials/routing/handler.md Updated documentation to clarify handler execution order and changed Add method signature to accept a slice.
docs/whats_new.md Documented new explicit main handler parameter requirement and updated examples for v3 method signatures.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant FiberApp
    participant Middleware1
    participant Middleware2
    participant MainHandler

    Client->>FiberApp: HTTP Request
    FiberApp->>Middleware1: Execute (if provided)
    Middleware1->>Middleware2: Execute (if provided)
    Middleware2->>MainHandler: Execute (main handler, always last)
    MainHandler-->>Client: Response
Loading

Possibly related PRs

Suggested labels

📒 Documentation, v3

Suggested reviewers

  • gaby
  • ReneWerner87

Poem

In the garden of code, where handlers align,
The main one now leads, the rest fall in line.
Middleware hops left to right,
The main handler shines bright.
With docs now as clear as the summer sunshine!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the documentation for routing methods by explicitly defining the required main handler and optional additional handlers, and by clarifying their execution order.

  • Updated the method signatures in documentation to clearly separate the main handler from additional handlers.
  • Revised code examples and comments in multiple files to reflect the new ordering and type safety improvements.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
docs/whats_new.md Updated changelog and examples to clarify the new routing method signature and order.
docs/partials/routing/handler.md Updated handler documentation to indicate the explicit separation of handlers.
app.go Revised inline documentation for routing methods to explain the new handler execution order.
Comments suppressed due to low confidence (1)

app.go:788

  • The documentation comments for the routing methods are repetitive. Consider referencing a shared documentation block or guideline to reduce redundancy and ease future maintenance.
func (app *App) Get(path string, handler Handler, handlers ...Handler) Router {

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.84%. Comparing base (f00e355) to head (1868f43).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3512      +/-   ##
==========================================
- Coverage   83.88%   83.84%   -0.05%     
==========================================
  Files         120      120              
  Lines       12278    12278              
==========================================
- Hits        10299    10294       -5     
- Misses       1555     1559       +4     
- Partials      424      425       +1     
Flag Coverage Δ
unittests 83.84% <ø> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
docs/partials/routing/handler.md (1)

29-34: Explicit “Handler Execution Order” section is helpful but refine punctuation.

Consider removing the colon after "handler" or making list-item punctuation consistent (either omit trailing punctuation on both items or include periods).

🧰 Tools
🪛 LanguageTool

[uncategorized] ~33-~33: Loose punctuation mark.
Context: ...r from additional handlers: - handler: The main route handler (required, execu...

(UNLIKELY_OPENING_PUNCTUATION)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f00e355 and 1868f43.

📒 Files selected for processing (3)
  • app.go (1 hunks)
  • docs/partials/routing/handler.md (2 hunks)
  • docs/whats_new.md (3 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/partials/routing/handler.md

[uncategorized] ~33-~33: Loose punctuation mark.
Context: ...r from additional handlers: - handler: The main route handler (required, execu...

(UNLIKELY_OPENING_PUNCTUATION)

docs/whats_new.md

[style] ~1471-~1471: Try moving the adverb to make the sentence clearer.
Context: ...P method registration methods have been updated to explicitly require a handler, followed by optional additional handle...

(SPLIT_INFINITIVE)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: unit (1.24.x, windows-latest)
  • GitHub Check: repeated
  • GitHub Check: Compare
🔇 Additional comments (17)
docs/partials/routing/handler.md (4)

11-23: Clarify required main handler and optional additional handlers in signatures.

The updated comments and method signatures clearly enforce that a main handler is mandatory and additional handlers are optional, improving API clarity and type safety.


37-40: Approve simple handlers example.

The example demonstrates usage without additional handlers and aligns with the new signature.


46-53: Approve additional-handlers example.

The annotated execution order (middleware → main handler) is clear and correctly positioned.


56-61: Approve multiple-methods example.

Demonstrates the new Add signature with a slice of methods and correct handler order.

app.go (11)

791-800: Document Get handler parameters and execution order.


806-815: Document Head handler parameters and execution order.


821-830: Document Post handler parameters and execution order.


836-845: Document Put handler parameters and execution order.


850-859: Document Delete handler parameters and execution order.


865-874: Document Connect handler parameters and execution order.


880-889: Document Options handler parameters and execution order.


895-903: Document Trace handler parameters and execution order.


910-919: Document Patch handler parameters and execution order.


924-933: Document Add method parameters and execution order.


940-949: Document All method parameters and execution order.

docs/whats_new.md (2)

241-246: Clarify v2 vs v3 handler signature enforcement.

The migration guide now explicitly states that the main handler is required and additional handlers follow, improving reader understanding.


253-275: Update method signatures in migration diff.

The diff accurately reflects signature changes for all HTTP registration methods and Add, aligning with v3 API.

@sixcolors sixcolors added the v3 label Jun 9, 2025
Comment thread app.go
// Get registers a route for GET methods that requests a representation
// of the specified resource. Requests using GET should only retrieve data.
//
// The first parameter 'handler' is the main route handler (executed last).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is wrong, the first handler is executed first
@sixcolors
app.Get("/users", mainHandler, handler1, handler2)
// Execution order: mainHandler -> handler1 -> handler2

in the order in which they were specified

Copy link
Copy Markdown
Member

@ReneWerner87 ReneWerner87 Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

@ReneWerner87 ReneWerner87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately wrong description

@sixcolors
Copy link
Copy Markdown
Member Author

The handler execution order was changed in Fiber v3 (in current beta as of Dec 2024 release) but reverted to the original behavior in PR #3321, which is in main but not yet released in a v3 beta. @ReneWerner87 to avoid confusion for users who adapted to the beta's execution order, I recommend highlighting this change in the next v3 release notes and adding a note to the documentation to clarify the switch back, as it may impact code written for the v3 beta release.

@sixcolors sixcolors closed this Jun 10, 2025
@ReneWerner87
Copy link
Copy Markdown
Member

ok good point

@ReneWerner87 ReneWerner87 deleted the docs-handler-execution-order branch July 30, 2025 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants