You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Albert Wang edited this page Apr 28, 2017
·
6 revisions
Welcome to the hyper2web wiki!
Documentation
fromhyper2webimportappif__name__=='__main__':
# A basic callback style API is providedasyncdefpost_echo(http, stream):
# this route essentially echo the data received back to clientprint('data received:')
print(str(stream.data, encoding='utf8'))
awaithttp.send_and_end(stream, stream.data)
app=app.App(static_file_handle='auto', root_route='index.html')
app.post('name', post_echo)
app.up()
class App
App(port=5000, root='./public)
The constructor of App class.
get(self, route: str, handler)
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)
class Stream
properties
stream_id: int:
the id of a H2 stream
headers: dict:
the headers of a HTTP request. Just a conventional headers