Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: medz/routingkit
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.1.0
Choose a base ref
...
head repository: medz/routingkit
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.1.1
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Mar 3, 2025

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    d5b5ba7 View commit details
  2. Copy the full SHA
    99f26b8 View commit details
  3. chore: bump version to 5.1.1

    medz committed Mar 3, 2025
    Copy the full SHA
    563bd2e View commit details
Showing with 86 additions and 11 deletions.
  1. +6 −0 CHANGELOG.md
  2. +46 −0 README.md
  3. +27 −3 llms.txt
  4. +7 −8 pubspec.yaml
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 5.1.1

### Documentation

- Improved pubspec.yaml with more descriptive information and optimized topics

## 5.1.0

### New Features
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ RoutingKit - A lightweight, high-performance router for Dart with an elegant obj
- 💪 **Type Safety**: Generic typing for your route handlers
- 🔍 **Comprehensive Matching**: Find single or all matching routes
- 🧰 **Object-Oriented API**: Clean, chainable methods for route management
- 🔠 **Case Sensitivity Options**: Configure whether path matching is case sensitive or not

## Installation

@@ -46,6 +47,15 @@ final router = createRouter<String>();
// For handling different data types
final dynamicRouter = createRouter<dynamic>();
// Create a case-insensitive router
final caseInsensitiveRouter = createRouter<String>(caseSensitive: false);
// Configure both case sensitivity and custom anyMethodToken
final customRouter = createRouter<String>(
caseSensitive: false,
anyMethodToken: 'ANY_METHOD',
);
```

### Adding Routes
@@ -125,6 +135,42 @@ router.find('GET', '/users'); // Matches
router.find('Get', '/users'); // Matches
```

### Advanced Configuration

#### Case Sensitivity

By default, RoutingKit performs case-sensitive path matching. You can make path matching case-insensitive:

```dart
// Create a case-insensitive router
final router = createRouter<String>(caseSensitive: false);
// Add a route with mixed case
router.add('GET', '/Users/:ID', 'user handler');
// All these will match the same route
final match1 = router.find('GET', '/users/123'); // Matches
final match2 = router.find('GET', '/Users/456'); // Matches
final match3 = router.find('GET', '/USERS/789'); // Matches
// Parameter names preserve their original case
print(match1.params); // {ID: 123}
```

#### Custom Method Tokens

You can customize the token used to represent any HTTP method:

```dart
final router = createRouter<String>(anyMethodToken: 'ANY_METHOD');
// Add routes with different methods
router.add('GET', '/api', 'get handler');
router.add(null, '/api', 'any handler'); // Uses custom token
router.find('POST', '/api')?.data; // Returns 'any handler'
```

## Example Applications

### HTTP Server Routing
30 changes: 27 additions & 3 deletions llms.txt
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ RoutingKit provides a flexible and efficient routing system with the following f
- Support for static, parameterized, and wildcard routes
- Efficient memory usage through a trie-based route storage
- Type-safe route handlers
- Configurable case sensitivity for path matching

## Core Components

@@ -25,9 +26,17 @@ RoutingKit provides a flexible and efficient routing system with the following f
## Usage Example

```dart
// Create a router with default settings (case-sensitive)
final router = createRouter<String>();

// Create a case-insensitive router
final caseInsensitiveRouter = createRouter<String>(caseSensitive: false);

// Add routes
router.add('GET', '/path', 'static route');
router.add('POST', '/path/:name', 'name route');

// Find routes
print(router.find('GET', '/path')); // => {data: static route}
```

@@ -37,18 +46,24 @@ print(router.find('GET', '/path')); // => {data: static route}
- **Route Matching**: Find the first matching route or all matching routes
- **Route Removal**: Remove routes by method, path, and data
- **HTTP Method Matching**: Specify different handling logic for different HTTP methods
- **Case Sensitivity**: Configure whether path matching is case-sensitive or not

## API Reference

### Router<T> Class

The `Router<T>` class is the core component of RoutingKit. It provides methods for managing and matching routes.

#### Properties:

- `String anyMethodToken`: Token used to represent any HTTP method
- `bool caseSensitive`: Whether path matching is case-sensitive

#### Key Methods:

- `void add(String? method, String path, T data)`: Adds a new route to the router
- `MatchedRoute<T>? find(String? method, String path)`: Finds the first route matching the given path and method
- `List<MatchedRoute<T>> findAll(String? method, String path)`: Finds all routes matching the given path and method
- `MatchedRoute<T>? find(String? method, String path, {bool includeParams = true})`: Finds the first route matching the given path and method
- `List<MatchedRoute<T>> findAll(String? method, String path, {bool includeParams = true})`: Finds all routes matching the given path and method
- `bool remove(String? method, String path, [T? data])`: Removes a route from the router

### MatchedRoute<T> Class
@@ -58,4 +73,13 @@ The `MatchedRoute<T>` class represents a matched route result.
#### Properties:

- `T data`: Data associated with the matched route
- `Map<String, String>? params`: Parameters extracted from the route, null if no parameters
- `Map<String, String>? params`: Parameters extracted from the route, null if no parameters

### createRouter<T> Function

Creates a new router instance with the specified configuration.

#### Parameters:

- `String anyMethodToken`: Token used to represent any HTTP method, defaults to 'routerkit-method://any'
- `bool caseSensitive`: Whether path matching is case-sensitive, defaults to true
15 changes: 7 additions & 8 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
name: routingkit
description: >-
Routing Kit
- Lightweight and fast router.
- A composable pure function routing kit.
version: 5.1.0
A lightweight, high-performance router for Dart with elegant API support for static,
parameterized, and wildcard routes. Perfect for HTTP servers, API gateways, and application routing.
version: 5.1.1
repository: https://github.com/medz/routingkit

funding:
- https://github.com/sponsors/medz

topics:
- router
- routing
- route
- fast-router
- routing-kit
- http
- path-matching
- trie
- performance

environment:
sdk: ^3.3.0