SHARE
TWEET

Untitled

a guest Jul 17th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from flask import Flask, request
  2. from flask_restplus import Api, Resource, fields
  3.  
  4. app = Flask(__name__)
  5. api = Api(app=app)
  6. model = api.model("simple_model", {'some_bool': fields.Boolean(required=False, default=False, description="A boolean"),
  7.                                    'some_int': fields.Integer(required=False, default=99, description="An integer")})
  8.  
  9.  
  10. @api.route('/foo')
  11. class SomeClass(Resource):
  12.  
  13.     @api.expect(model)
  14.     def post(self):
  15.         return request.json
  16.  
  17.  
  18. if __name__ == '__main__':
  19.     app.run(host='localhost', port=8000, threaded=False, debug=True)
  20.      
  21. {'some_bool': True, 'some_int': 20}
  22.  
  23. {'some_bool': True}
  24.  
  25. {'some_int': 20}
  26. None
  27.      
  28. {'some_bool': True, 'some_int': 20}
  29.  
  30. {'some_bool': True, 'some_int': 99}
  31.  
  32. {'some_bool': False, 'some_int': 20}
  33.  
  34. {'some_bool': False, 'some_int': 99}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top