-
Notifications
You must be signed in to change notification settings - Fork 5
Home
Albert Wang edited this page Apr 28, 2017
·
6 revisions
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