Created
December 1, 2014 09:57
-
-
Save tarasn/fe5afead2ff89b9f124d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from flask import Flask, request | |
| from flask.ext.restful import Resource, Api | |
| import json | |
| app = Flask(__name__) | |
| api = Api(app) | |
| projects = {} | |
| class MyEncoder(json.JSONEncoder): | |
| def encode(self, o): | |
| d = { | |
| 'AAA_A':o['aaa'] | |
| } | |
| return d | |
| class MyDecoder(json.JSONDecoder): | |
| def decode(self, o): | |
| d = { | |
| 'aaa':o['AAA_A'] | |
| } | |
| return d | |
| class BuildProject(Resource): | |
| def get(self): | |
| return json.dumps({'aaa':'aaa'},cls=MyEncoder) | |
| class BuildProject2(Resource): | |
| def post(self): | |
| return json.loads(request.get_json(),cls=MyDecoder) | |
| api.add_resource(BuildProject, '/test-encode/') | |
| api.add_resource(BuildProject2, '/test-dencode/') | |
| if __name__ == '__main__': | |
| app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment