Skip to content

Commit 6c50082

Browse files
committed
fix: demonstrate params in context
1 parent 6efed03 commit 6c50082

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lightbug.🔥

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ from lightbug_http import *
22

33
struct HelloWorld(HTTPHandler):
44
fn handle(self, context: Context) -> HTTPResponse:
5-
return Success("Hello, World!")
5+
var name = context.params.get("username", "world")
6+
return Success("Hello, " + name + "!")
67

78
fn main() raises:
89
var router = RouterMiddleware()

lightbug_http/middleware.mojo

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ from lightbug_http.service import HTTPService
88
@value
99
struct Context:
1010
var request: HTTPRequest
11-
var params: Dict[String, String]
11+
var params: Dict[String, AnyType]
1212

1313
fn __init__(inout self, request: HTTPRequest):
1414
self.request = request
15-
self.params = Dict[String, String]()
15+
self.params = Dict[String, AnyType]()
1616

1717

1818
## Middleware is an interface for processing HTTP requests.
@@ -24,6 +24,7 @@ trait Middleware:
2424
...
2525

2626
## MiddlewareChain is a chain of middleware that processes the request.
27+
## The chain is a linked list of middleware objects.
2728
@value
2829
struct MiddlewareChain(HTTPService):
2930
var root: Middleware

0 commit comments

Comments
 (0)