Define Server API scheme
API contains optional endpoints defined by list of Intents
This commit is contained in:
@@ -11,10 +11,21 @@ python3 -m pip install "uvicorn[standard]"
|
||||
After importing an app such as `main.py`:
|
||||
|
||||
```python
|
||||
from typing import List
|
||||
from src.vue_apps_py.security import SecurityHelper
|
||||
from src.vue_apps_py.server import VueApp
|
||||
from src.vue_apps_py.server import VueApp, name_intents
|
||||
from src.vue_apps_py.client import ClientAPI
|
||||
from src.vue_apps_py.server_utils.models import Intent
|
||||
from src.vue_apps_py.server_utils.intents import Intent, InlineQuery
|
||||
from src.vue_apps_py.server_utils.models import AutoModel, SuggestionsModel
|
||||
|
||||
|
||||
def autocomplete_handler(query_model: AutoModel) -> SuggestionsModel:
|
||||
# Just log the query
|
||||
print(query_model.json())
|
||||
|
||||
# Send back empty model
|
||||
return SuggestionsModel()
|
||||
|
||||
|
||||
# Initialize API
|
||||
api = ClientAPI(client_id='vue-app-0', client_secret='abccf12389efab222')
|
||||
@@ -22,8 +33,12 @@ api = ClientAPI(client_id='vue-app-0', client_secret='abccf12389efab222')
|
||||
# Prepare Security
|
||||
key_holder = SecurityHelper(public_key='abbcbbbcaksjdhf/skdjhfnnsn/sjdkfjj21234=')
|
||||
|
||||
# Define intents
|
||||
intents: List[Intent] = [InlineQuery(autocomplete_handler)]
|
||||
named_intents = name_intents(intents)
|
||||
|
||||
# Get Vue Application Server
|
||||
vue_app = VueApp(client_api=api, security_helper=key_holder, intents=[Intent.INLINE_QUERY], debug=True)
|
||||
vue_app = VueApp(client_api=api, security_helper=key_holder, named_intents=named_intents, debug=True)
|
||||
```
|
||||
|
||||
You can launch web server:
|
||||
|
||||
Reference in New Issue
Block a user