-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
35 lines (25 loc) · 965 Bytes
/
example.py
File metadata and controls
35 lines (25 loc) · 965 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
#!/usr/bin/env python3
"""Simple example showing Rupy routing"""
from __future__ import annotations
from rupy import Request
from rupy import Response
from rupy import Rupy
# Create a Rupy application
app = Rupy()
@app.route('/', methods=['GET'])
def hello_world(request: Request) -> Response:
return Response('Hello, World!')
@app.route('/user/<username>', methods=['GET'])
def hello_user(request: Request, username: str) -> Response:
return Response(f"Hello, {username}!")
@app.route('/echo', methods=['POST'])
def echo(request: Request) -> Response:
return Response(f"Echo: {request.body}")
if __name__ == '__main__':
# Run the server on localhost:8000
print('Starting Rupy server with routing enabled...')
print('Try:')
print(' curl http://127.0.0.1:8000/')
print(' curl http://127.0.0.1:8000/user/alice')
print(" curl -X POST -d 'test data' http://127.0.0.1:8000/echo")
app.run(host='127.0.0.1', port=8000)