You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
YellWOWPages/yellow/api.py

26 lines
701 B

from quart import render_template, request, redirect, url_for, jsonify, Blueprint, abort, flash, send_from_directory, current_app
import settings
from yellow.models import User
bp_api = Blueprint('bp_api', __name__, url_prefix='/api')
@bp_api.get("/")
async def api_root():
return await render_template('api.html')
@bp_api.get('/user/')
async def api_all():
return jsonify([u.to_json(ignore_key='id') for u in User.select()])
@bp_api.get('/user/<path:needle>')
async def api_search(needle: str):
try:
return jsonify([u.to_json(ignore_key='id') for u in await User.search(needle)])
except Exception as ex:
current_app.logger.error(ex)
return jsonify([])