def greeting_handle(ws): while True: message = ws.wait() if message is None: break data = json.loads(message) greeting = random_greeting(data['name']) ws.send(json.dumps({ 'greeting': greeting }))
async def greeting(websocket: WebSocket): await websocket.accept() while True: try: data = await websocket.receive_json() greeting = random_greeting(data['name']) await websocket.send_json({'greeting': greeting}) except: await websocket.close() break
async def greeting(websocket, path): if path == '/greeting': while True: try: message = await websocket.recv() data = json.loads(message) greeting = random_greeting(data['name']) await websocket.send(json.dumps({'greeting': greeting})) except: await websocket.close() break
def on_message(self, sid, data): greeting = random_greeting(data['name']) self.send({ 'greeting': greeting })
def post(self): data = json.loads(self.request.body) greeting = random_greeting(data['name']) self.set_header('Content-Type', 'application/json') self.write(json.dumps({'greeting': greeting}))
def greeting(data): greeting = random_greeting(data['name']) send({ 'greeting': greeting })
def greeting(data: Data): greeting = random_greeting(data.name) return { 'greeting': greeting }
def greeting(request): data = request.json_body greeting = random_greeting(data['name']) return {'greeting': greeting}
def greeting(): json = request.get_json() name = json.get('name') greeting = random_greeting(name) return jsonify(greeting=random_greeting(name))
def on_message(self, message): data = json.loads(message) greeting = random_greeting(data['name']) self.write_message({'greeting': greeting})