-
Notifications
You must be signed in to change notification settings - Fork 5
Home
Welcome to the hyper2web wiki!
from hyper2web import app
if __name__ == '__main__':
# A basic callback style API is provided
async def post_echo(http, stream):
# this route essentially echo the data received back to client
print('data received:')
print(str(stream.data, encoding='utf8'))
await http.send_and_end(stream, stream.data)
app = app.App(static_file_handle='auto', root_route='index.html')
app.post('name', post_echo)
app.up()
The constructor of App class.
route: the restful api handler: an async function which accepts 2 arguments, a HTTP instance and a HTTP/2 stream
async def get_name(http: http.HTTP, stream: http.Stream):
print('GET name hit')
await handler.send_and_end('GET name hit')
app.get('name', get_name)
stream_id: int
:
the id of a H2 stream
headers: dict
:
the headers of a HTTP request. Just a conventional headers
data
:
data of this request. Could be None
You should never construct a HTTP instance yourself. You only get it from the parameter of your router handler function.
await send_and_end(stream: http.Stream, data: bytes)
:
Send data to client and end this stream.
await send_file(stream: http.Stream, file_path: str)
:
Send this file to client and end this stream. You should always use this method to send files.
If you use send_and_end
, you have to manage flow control yourself.
await send_error(stream. http.Stream, error: int)
:
Send a HTTP error code to client.