# This example does an AJAX lookup and is in CoffeeScript
$('.typeahead').typeahead(
# source can be a function
source: (typeahead, query) ->
# this function receives the typeahead object and the query string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.get("/sse/publish") | |
async def get(channel: str = "default", redis: Redis = Depends(depends_redis)): | |
await redis.publish(channel=channel, message="Hello world!") | |
return "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.get("/sse/stream") | |
async def stream(): | |
return EventSourceResponse(subscribe) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async def subscribe(channel: str, redis: Redis) -> AsyncGenerator: | |
(subscription,) = await redis.subscribe(channel=Channel(channel, False)) | |
while await subscription.wait_message(): | |
yield {"event": "message", "data": await subscription.get()} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aioredis import Channel, Redis | |
from fastapi import FastAPI | |
from fastapi.params import Depends | |
from fastapi_plugins import depends_redis, redis_plugin | |
from sse_starlette.sse import EventSourceResponse | |
from starlette.responses import HTMLResponse | |
html = """ | |
<!DOCTYPE html> | |
<html> |