importaiohttpimportaiohttp.webimportasabimportasab.webimportasab.web.restimportasab.web.sessionclassMyApplication(asab.Application):asyncdefinitialize(self):# Loading the web service moduleself.add_module(asab.web.Module)# Locate web servicewebsvc=self.get_service("asab.WebService")# Create a dedicated web containercontainer=asab.web.WebContainer(websvc,'example:web')# Enable exception to JSON exception middlewarecontainer.WebApp.middlewares.append(asab.web.rest.JsonExceptionMiddleware)# Add routescontainer.WebApp.router.add_post('/api/jsonfile',self.jsonfile)print("""Test file schema example with curl: $ curl http://localhost:8080/api/jsonfile -X POST -H "Content-Type: application/json" -d '{"key2":666}'""")container.WebApp.router.add_post('/api/jsondict',self.jsondict)print("""Test dict schema example with curl: $ curl http://localhost:8080/api/jsondict -X POST -H "Content-Type: application/json" -d '{"key1":"sample text"}'or as form $ curl http://localhost:8080/api/jsondict -X POST -d "key1=sample%20text"""")@asab.web.rest.json_schema_handler('./data/sample_json_schema.json')asyncdefjsonfile(self,request,*,json_data):returnaiohttp.web.Response(text='Valid data {}\n'.format(json_data))@asab.web.rest.json_schema_handler({'type':'object','properties':{'key1':{'type':'string'},'key2':{'type':'number'},}})asyncdefjsondict(self,request,*,json_data):returnaiohttp.web.Response(text='Valid data {}\n'.format(json_data))if__name__=='__main__':app=MyApplication()app.run()