-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
36 lines (31 loc) · 1003 Bytes
/
example.py
File metadata and controls
36 lines (31 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# main.py
from Router import Router
from utils.HttpResponse import HttpResponse
from constants.HttpConstants import *
from server import start_server
from utils.HttpRequest import HttpRequest
router = Router()
@router.route('/test1', HTTP_METHOD_GET)
def test1( httpRequest):
return HttpResponse().prepareResponse(
HTTP_200_OK,
CONTENT_TYPE_TEXT_HTML,
"<html><body><h1>test 11!</h1></body></html>"
)
@router.route('/test2', HTTP_METHOD_GET)
def test2( httpRequest):
print(httpRequest.query_params)
return HttpResponse().prepareResponse(
HTTP_200_OK,
CONTENT_TYPE_TEXT_HTML,
"<html><body><h1>test 22!</h1></body></html>"
)
def default_handler( httpRequest):
return HttpResponse().prepareResponse(
HTTP_404_NOT_FOUND,
CONTENT_TYPE_TEXT_HTML,
"<html><body><h1>Please implement this method!</h1></body></html>"
)
router.not_found_handler_method(default_handler)
# Start the server
start_server(router)