|
@@ -0,0 +1,31 @@
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+
|
|
|
+from eve import Eve
|
|
|
+from flask import request
|
|
|
+import json
|
|
|
+
|
|
|
+port = 8080
|
|
|
+host = '127.0.0.1'
|
|
|
+
|
|
|
+app = Eve()
|
|
|
+
|
|
|
[email protected]_request
|
|
|
+def add_correct_headers(response):
|
|
|
+ path = request.path
|
|
|
+ if path == '/json':
|
|
|
+ response.headers['Content-Type'] = 'application/json'
|
|
|
+ elif path == '/plaintext':
|
|
|
+ response.headers['Content-Type'] = 'text/plain'
|
|
|
+ return response
|
|
|
+
|
|
|
[email protected]('/plaintext')
|
|
|
+def hello_world():
|
|
|
+ return 'Hello, World!'
|
|
|
+
|
|
|
[email protected]('/json')
|
|
|
+def jsonHello():
|
|
|
+ hello = {'message': 'Hello, World!'}
|
|
|
+ return json.dumps(hello)
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ app.run(host=host, port=port)
|