@@ -0,0 +1,45 @@
|
||||
from kaya import BugisApp, HttpContext, HttpMethod
|
||||
from typing import List
|
||||
|
||||
class Hello(BugisApp):
|
||||
pass
|
||||
|
||||
# async def handle_request(self, ctx: HttpContext) -> None:
|
||||
# async for chunk in ctx.request_body:
|
||||
# print(chunk.decode())
|
||||
# await ctx.send_str(200, 'Hello World')
|
||||
|
||||
|
||||
app = BugisApp()
|
||||
|
||||
|
||||
@app.GET('/hello')
|
||||
@app.GET('/hello2')
|
||||
async def handle_request(ctx: HttpContext) -> None:
|
||||
async for chunk in ctx.request_body:
|
||||
print(chunk.decode())
|
||||
await ctx.send_str(200, 'Hello World')
|
||||
|
||||
@app.GET('/hello/alice')
|
||||
async def hello_alice(ctx: HttpContext) -> None:
|
||||
async for _ in ctx.request_body:
|
||||
pass
|
||||
await ctx.send_str(200, 'Hello Alice 2')
|
||||
|
||||
@app.GET('/hello/*')
|
||||
async def hello_wildcard(ctx: HttpContext, args: List[str]) -> None:
|
||||
async for _ in ctx.request_body:
|
||||
pass
|
||||
await ctx.send_str(200, f'Hello {args[0]}')
|
||||
|
||||
@app.GET('/hello/bob/marley')
|
||||
async def hello_bob_marley(ctx: HttpContext) -> None:
|
||||
async for _ in ctx.request_body:
|
||||
pass
|
||||
await ctx.send_str(200, f'Hello bob Marley')
|
||||
|
||||
@app.route('/hello/*', HttpMethod.PUT, recursive=True)
|
||||
async def handle_put_request(ctx: HttpContext, _: List[str]) -> None:
|
||||
async for chunk in ctx.request_body:
|
||||
print(chunk.decode())
|
||||
await ctx.send_str(200, 'Message received')
|
||||
Reference in New Issue
Block a user