In order to rewrite a basic Flask example with Flask-Restplus, I would like to create a POST with only a plain text body.
The below example does what I want, but of course the documentation is not correct as I do not expect a mapping with fields, but rather the value directly.
How can I adjust the example, so that the UI Shows that I need a plain text payload (without fields)?
from flask import Flask, request, jsonify
from flask_restplus import Resource, Api, fields
app = Flask(__name__)
api = Api(app)
all_data = []
@api.route('/data')
class Data(Resource):
def get(self):
return jsonify(all_data)
@api.expect(api.model("NewData", {"newdata": fields.String}))
def post(self):
json = request.json
print("Adding", json)
all_data.append(json)
return ""
if __name__ == '__main__':
app.run(debug=True, port=8080)
It is important that I want my data in the payload and not the URL. And while JSON input with fields might be a more solid solution, I would like to finish this version first.
(And if I go for JSON payload (not URL), is there a way to show separate input lines for the fields, such that Flask-Restplus will assemble the JSON?)