Permalink
Browse files

Add examples used Flask-JSONRPC

  • Loading branch information...
nycholas committed Dec 16, 2012
1 parent b743310 commit 2884b68748ea3894e71208312c7a4cfb7e763b01
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Copyright (c) 2012, Cenobit Technologies, Inc. http://cenobit.es/
+# All rights reserved.
+import os
+import sys
+
+from flask import Flask
+
+PROJECT_DIR, PROJECT_MODULE_NAME = os.path.split(
+ os.path.dirname(os.path.realpath(__file__))
+)
+
+FLASK_JSONRPC_PROJECT_DIR = os.path.join(PROJECT_DIR, os.pardir)
+if os.path.exists(FLASK_JSONRPC_PROJECT_DIR) \
+ and not FLASK_JSONRPC_PROJECT_DIR in sys.path:
+ sys.path.append(FLASK_JSONRPC_PROJECT_DIR)
+
+from flask_jsonrpc import JSONRPC
+
+app = Flask(__name__)
+jsonrpc = JSONRPC(app, '/api')
+
+@jsonrpc.method('app.index')
+def index():
+ return 'Welcome to Flask JSON-RPC'
+
+
+if __name__ == '__main__':
+ app.run()
@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2012, Cenobit Technologies, Inc. http://cenobit.es/
+# All rights reserved.
@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2012, Cenobit Technologies, Inc. http://cenobit.es/
+# All rights reserved.
+from flask import Blueprint
+
+from modular import jsonrpc
+
+mod = Blueprint('article', __name__)
+jsonrpc.register_blueprint(mod)
+
+@jsonrpc.method('article.index')
+def index():
+ return 'Welcome to Article API'
@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2012, Cenobit Technologies, Inc. http://cenobit.es/
+# All rights reserved.
+from flask import Blueprint
+
+from modular import jsonrpc
+
+mod = Blueprint('user', __name__)
+jsonrpc.register_blueprint(mod)
+
+@jsonrpc.method('user.index')
+def index():
+ return 'Welcome to User API'
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Copyright (c) 2012, Cenobit Technologies, Inc. http://cenobit.es/
+# All rights reserved.
+import os
+import sys
+
+from flask import Flask
+
+PROJECT_DIR, PROJECT_MODULE_NAME = os.path.split(
+ os.path.dirname(os.path.realpath(__file__))
+)
+
+FLASK_JSONRPC_PROJECT_DIR = os.path.join(PROJECT_DIR, os.pardir)
+if os.path.exists(FLASK_JSONRPC_PROJECT_DIR) \
+ and not FLASK_JSONRPC_PROJECT_DIR in sys.path:
+ sys.path.append(FLASK_JSONRPC_PROJECT_DIR)
+
+from flask_jsonrpc import JSONRPC
+
+app = Flask(__name__)
+jsonrpc = JSONRPC(app, '/api')
+
+@jsonrpc.method('app.index')
+def index():
+ return 'Welcome to Flask JSON-RPC'
+
+import api.user
+import api.article
+
+
+if __name__ == '__main__':
+ app.run()

0 comments on commit 2884b68

Please sign in to comment.