Skip to content
Albert Wang edited this page Apr 26, 2017 · 6 revisions

Welcome to the hyper2web wiki!

Documentation

from hyper2web import app
app = app.App()

class App

init(self, port=5000, root='./public', static_file_handle='auto', root_route='index.html')

The constructor of App class.

get(self, route: str, handler=None)

route: the restful api handler: an async function which accepts only one argument, an EndPointHandler

async def get_name(handler):
	print('GET name hit')
	await handler.send_and_end('GET name hit')

app.get('name', get_name)

class EndPointHandler

A top level API user should never construct it. It is only passed by the framework to the app.get's async callback function.

async def send_and_end(self, data)

send data to the client. data type could be any, but recommendation is str this will end a HTTP/2 stream

async def send_file(self, file_path)

send a file in your filesystem this will end a HTTP/2 stream

If you want to send a file, this function is recommended. If you use the send_and_end function, you have to do the flow control yourself, which is not fun.

Clone this wiki locally