Skip to content

refactor: remove http_methods dependency#513

Open
yuchengpersonal wants to merge 3 commits intodart-lang:masterfrom
yuchengpersonal:fix/remove-http-methods-dependency
Open

refactor: remove http_methods dependency#513
yuchengpersonal wants to merge 3 commits intodart-lang:masterfrom
yuchengpersonal:fix/remove-http-methods-dependency

Conversation

@yuchengpersonal
Copy link
Copy Markdown

Summary

Remove the external http_methods package dependency and replace it with an inlined implementation, as suggested in #512.

Motivation

The http_methods package is not maintained by the Dart team. Removing this external dependency is a prerequisite for potentially using shelf_router in the Dart SDK.

Changes

  • Added pkgs/shelf_router/lib/src/http_methods.dart — contains the full IANA HTTP method registry and the isHttpMethod() function
  • Updated router.dart to use the local http_methods.dart import instead of the external package
  • Updated shelf_router.dart barrel file to re-export isHttpMethod for downstream consumers
  • Updated shelf_router_generator to import isHttpMethod from shelf_router instead of http_methods
  • Removed http_methods dependency from both shelf_router/pubspec.yaml and shelf_router_generator/pubspec.yaml

API Compatibility

This is a fully backward-compatible change:

  • isHttpMethod() retains the same signature and behavior (case-insensitive check against IANA methods)
  • The httpMethods constant set is available for internal use
  • All existing public APIs remain unchanged

Checklist

  • Replaced external dependency with inlined implementation
  • Updated both shelf_router and shelf_router_generator packages
  • IANA method list is up-to-date (includes QUERY from RFC-ietf-httpbis-safe-method-w-body-14)
  • No breaking API changes

Fixes #512

🐙 Generated with OpenClaw

Replace the external `http_methods` package with an inlined
`http_methods.dart` file in `shelf_router`. This removes the
dependency on a package not maintained by the Dart team, which is a
prerequisite for using `shelf_router` in the Dart SDK.

Changes:
- Add `pkgs/shelf_router/lib/src/http_methods.dart` with the full
  IANA HTTP method registry and `isHttpMethod()` function
- Update `router.dart` to use the local import
- Export `isHttpMethod` from `shelf_router.dart` barrel file
- Update `shelf_router_generator` to import from `shelf_router`
  instead of `http_methods`
- Remove `http_methods` from both `pubspec.yaml` files

Fixes dart-lang#512

Co-Authored-By: Claude <noreply@anthropic.com>
@google-cla
Copy link
Copy Markdown

google-cla bot commented Mar 19, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the shelf_router package by eliminating its reliance on the unmaintained http_methods external dependency. The core functionality for identifying HTTP methods has been integrated directly into the shelf_router package, ensuring better control and paving the way for potential future integration with the Dart SDK. This change maintains full API compatibility and updates all internal references to use the new inlined implementation.

Highlights

  • Dependency Removal: The external http_methods package dependency has been removed from both shelf_router and shelf_router_generator.
  • Inlined Implementation: The functionality previously provided by the http_methods package, including the full IANA HTTP method registry and the isHttpMethod() function, has been inlined into a new file: pkgs/shelf_router/lib/src/http_methods.dart.
  • Import Updates: router.dart and shelf_router_generator have been updated to utilize the new local http_methods.dart implementation instead of the external package.
  • API Compatibility: This change is fully backward-compatible, ensuring that isHttpMethod() retains its original signature and behavior, and all existing public APIs remain unchanged.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively removes the http_methods dependency by inlining its functionality, which is a great step towards reducing external dependencies. The implementation in http_methods.dart is clean and efficient. I've found one minor issue regarding an import path in the generator package that should be adjusted to rely on the public API of shelf_router instead of its internal files. Otherwise, the changes look solid.

import 'package:build/build.dart' show BuildStep, log;
import 'package:code_builder/code_builder.dart' as code;
import 'package:http_methods/http_methods.dart' show isHttpMethod;
import 'package:shelf_router/src/http_methods.dart' show isHttpMethod;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To adhere to best practices, you should avoid importing files from another package's lib/src directory. Since isHttpMethod is now exported from package:shelf_router/shelf_router.dart, it's part of the public API. Please update this import to use the public package URI.

This ensures that shelf_router_generator relies on the stable, public API of shelf_router rather than its internal implementation details, which could change without notice.

Suggested change
import 'package:shelf_router/src/http_methods.dart' show isHttpMethod;
import 'package:shelf_router/shelf_router.dart' show isHttpMethod;

Address review feedback from gemini-code-assist: import isHttpMethod from
the public package:shelf_router/shelf_router.dart instead of the internal
src/http_methods.dart path. This ensures shelf_router_generator relies on
the stable, public API.
@yuchengpersonal
Copy link
Copy Markdown
Author

Thanks for the suggestion! I will update the import to use the public API as recommended.

- Export RouterEntry from shelf_router.dart to allow shelf_router_generator
to use public API instead of importing from lib/src
- Update shelf_router_generator to import RouterEntry from public API

Addresses review feedback from gemini-code-assist
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.

Avoid http_methods dependency

1 participant