How to get POSTed JSON in Flask?

前端 未结 10 1140
隐瞒了意图╮
隐瞒了意图╮ 2020-11-21 06:35

I\'m trying to build a simple API using Flask, in which I now want to read some POSTed JSON. I do the POST with the Postman Chrome extension, and the JSON I POST is simply <

10条回答
  •  心在旅途
    2020-11-21 06:56

    Assuming you've posted valid JSON with the application/json content type, request.json will have the parsed JSON data.

    from flask import Flask, request, jsonify
    
    app = Flask(__name__)
    
    
    @app.route('/echo', methods=['POST'])
    def hello():
       return jsonify(request.json)
    

提交回复
热议问题