or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

brokers.mddecorators.mddiscovery.mdhttp.mdindex.mdrequests.mdrouters.mdscheduling.mdspecs.mdsystem-utils.md

routers.mddocs/

0

# Routing System

1

2

The routing system provides abstract interfaces and concrete implementations for handling different types of route registration and management. Routers aggregate decorated handlers and provide structured access to routing information across different transport types.

3

4

## Capabilities

5

6

### Base Router Interface

7

8

Abstract base class that defines the routing contract for all transport types.

9

10

```python { .api }

11

from abc import ABC, abstractmethod

12

from typing import Dict, List, Callable

13

14

class Router(ABC):

15

routes: Dict[Any, Callable]

16

17

@abstractmethod

18

def build_routes(self) -> None: ...

19

20

def get_routes(self) -> Dict[Any, Callable]: ...

21

```

22

23

**Usage Examples:**

24

25

```python

26

from minos.networks import Router

27

28

# Routers are typically used internally by the framework

29

# They aggregate decorated handlers automatically

30

```

31

32

### Broker Router

33

34

Router implementation for message broker handlers, collecting broker-decorated methods.

35

36

```python { .api }

37

class BrokerRouter(Router):

38

def __init__(self): ...

39

routes: Dict[BrokerEnrouteDecorator, Callable]

40

41

def build_routes(self) -> None: ...

42

```

43

44

**Usage Examples:**

45

46

```python

47

from minos.networks import BrokerRouter, enroute

48

49

class MessageService:

50

@enroute.broker.command("user.create")

51

async def create_user(self, request):

52

return Response({"status": "created"})

53

54

# Router automatically discovers and manages broker routes

55

broker_router = BrokerRouter()

56

broker_router.build_routes()

57

```

58

59

### HTTP Router

60

61

Router implementation for HTTP handlers, managing REST endpoint registration.

62

63

```python { .api }

64

class HttpRouter(Router):

65

def __init__(self): ...

66

routes: Dict[HttpEnrouteDecorator, Callable]

67

68

def build_routes(self) -> None: ...

69

```

70

71

### REST HTTP Router

72

73

Specialized HTTP router for RESTful service endpoints.

74

75

```python { .api }

76

class RestHttpRouter(HttpRouter):

77

def __init__(self): ...

78

routes: Dict[RestEnrouteDecorator, Callable]

79

80

def build_routes(self) -> None: ...

81

```

82

83

**Usage Examples:**

84

85

```python

86

from minos.networks import RestHttpRouter, enroute

87

88

class UserAPI:

89

@enroute.rest.query("/users/{user_id}", method="GET")

90

async def get_user(self, request):

91

return Response({"id": "123", "name": "John"})

92

93

@enroute.rest.command("/users", method="POST")

94

async def create_user(self, request):

95

return Response({"id": "456"}, status=201)

96

97

# Router manages REST endpoint registration

98

rest_router = RestHttpRouter()

99

rest_router.build_routes()

100

```

101

102

### Periodic Router

103

104

Router implementation for scheduled/periodic task handlers.

105

106

```python { .api }

107

class PeriodicRouter(Router):

108

def __init__(self): ...

109

routes: Dict[PeriodicEnrouteDecorator, Callable]

110

111

def build_routes(self) -> None: ...

112

```

113

114

**Usage Examples:**

115

116

```python

117

from minos.networks import PeriodicRouter, enroute

118

119

class ScheduledTasks:

120

@enroute.periodic.event("0 */5 * * * *") # Every 5 minutes

121

async def cleanup_task(self, request):

122

# Perform cleanup

123

return Response({"status": "cleanup_completed"})

124

125

@enroute.periodic.event("0 0 * * * *") # Every hour

126

async def hourly_report(self, request):

127

return Response({"report": "generated"})

128

129

# Router manages periodic task registration

130

periodic_router = PeriodicRouter()

131

periodic_router.build_routes()

132

```

133

134

## Architecture Integration

135

136

Routers work together with the decorator system and ports to provide comprehensive routing:

137

138

- **Discovery Phase**: Routers scan for decorated methods during initialization

139

- **Registration Phase**: Routes are built and stored in the routes dictionary

140

- **Execution Phase**: Ports use routers to dispatch incoming requests to appropriate handlers

141

- **Type Safety**: Each router type handles specific decorator types, ensuring proper routing

142

143

The routing system enables the framework's unified decorator approach while maintaining clean separation between different transport mechanisms.