Skip to content

Instantly share code, notes, and snippets.

@tarasn
Created December 1, 2014 09:57
Show Gist options
  • Save tarasn/fe5afead2ff89b9f124d to your computer and use it in GitHub Desktop.
Save tarasn/fe5afead2ff89b9f124d to your computer and use it in GitHub Desktop.
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