Skip to content
Albert Wang edited this page Apr 28, 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 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()

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

data:
data of this request. Could be None

class HTTP

Clone this wiki locally