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

Welcome to the hyper2web wiki!

Documentation

from hyper2web import app

if __name__ == '__main__':

	# A basic callback style API is provided
	async def get_name(handler):
		print('GET name hit')
		await handler.send_and_end('GET name hit')

	async def post_message(handler):
		print('Data Received:', str(handler.data, encoding='utf8'))
		await handler.send_and_end(str(handler.data, encoding='utf8'))

	app = app.App(port=5000)	
	app.get('name', get_name)
	app.post('message', post_message)
	app.up()

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