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