@@ -97,25 +97,22 @@ Once you have a Mojo project set up locally,
97
97
For example, to make a ` Printer ` service that prints some details about the request to console:
98
98
99
99
``` mojo
100
- from lightbug_http import *
100
+ from lightbug_http.http import HTTPRequest, HTTPResponse, OK
101
+ from lightbug_http.strings import to_string
102
+ from lightbug_http.header import HeaderKey
101
103
102
104
@value
103
105
struct Printer(HTTPService):
104
106
fn func(mut self, req: HTTPRequest) raises -> HTTPResponse:
105
- var uri = req.uri
106
- print("Request URI: ", to_string(uri.request_uri))
107
-
108
- var header = req.headers
109
- print("Request protocol: ", req.protocol)
110
- print("Request method: ", req.method)
111
- print(
112
- "Request Content-Type: ", to_string(header[HeaderKey.CONTENT_TYPE])
113
- )
114
-
115
- var body = req.body_raw
116
- print("Request Body: ", to_string(body))
117
-
118
- return OK(body)
107
+ print("Request URI:", req.uri.request_uri)
108
+ print("Request protocol:", req.protocol)
109
+ print("Request method:", req.method)
110
+ if HeaderKey.CONTENT_TYPE in req.headers:
111
+ print("Request Content-Type:", req.headers[HeaderKey.CONTENT_TYPE])
112
+ if req.body_raw:
113
+ print("Request Body:", to_string(req.body_raw))
114
+
115
+ return OK(req.body_raw)
119
116
```
120
117
121
118
6 . Start a server listening on a port with your service like so.
0 commit comments