Update for public https://habr.com/post/421887/
This commit is contained in:
12
myapp/ns_api/README.html
Normal file
12
myapp/ns_api/README.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<a href="https://github.com/cenobites/flask-jsonrpc">https://github.com/cenobites/flask-jsonrpc</a>
|
||||
|
||||
<pre>
|
||||
curl -i -X POST \
|
||||
-H "Content-Type: application/json; indent=4" \
|
||||
-d '{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "users.getList",
|
||||
"params": {},
|
||||
"id": "1"
|
||||
}' http://localhost:8000/api
|
||||
</pre>
|
||||
16
myapp/ns_api/__init__.py
Normal file
16
myapp/ns_api/__init__.py
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
__author__ = 'RemiZOffAlex'
|
||||
__copyright__ = '(c) RemiZOffAlex'
|
||||
__license__ = 'MIT'
|
||||
__email__ = 'remizoffalex@mail.ru'
|
||||
__url__ = 'http://remizoffalex.ru'
|
||||
|
||||
from flask_jsonrpc import JSONRPC
|
||||
|
||||
from .. import app
|
||||
|
||||
jsonrpc = JSONRPC(app, '/api')
|
||||
|
||||
from . import user
|
||||
28
myapp/ns_api/user.py
Normal file
28
myapp/ns_api/user.py
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
__author__ = 'RemiZOffAlex'
|
||||
__copyright__ = '(c) RemiZOffAlex'
|
||||
__license__ = 'MIT'
|
||||
__email__ = 'remizoffalex@mail.ru'
|
||||
__url__ = 'http://remizoffalex.ru'
|
||||
|
||||
from flask import abort, escape
|
||||
|
||||
from . import jsonrpc
|
||||
from .. import models
|
||||
|
||||
|
||||
@jsonrpc.method('users.getList')
|
||||
def users_getList():
|
||||
"""
|
||||
Показать список пользователей
|
||||
"""
|
||||
users = models.db_session.query(
|
||||
models.User
|
||||
).all()
|
||||
|
||||
result = []
|
||||
for item in users:
|
||||
result.append(item.as_dict())
|
||||
return result
|
||||
Reference in New Issue
Block a user