Multiple HttpPost method in Web API with Python Flask

Multiple HttpPost method in Web API with Python Flask

Python-Flash-Sedat-Ozdemir

Hello guys, I’m gonna show you today, how can we create multiple HttpPost web api with Python Flask. Sometimes we need to basic scripts in hard work day. You can speed up at your work with customising this script. Ex: You can check exist users using multiple HttpPost on your Linux server over cURL command. I will write this article later.

from flask import Flask, flash, request, redirect, url_for #Import Flask

app = Flask(__name__)
app.config["DEBUG"] = True
@app.route('/api/example', methods=['POST']) #Use POST method

def example():
    Name = request.form.getlist('name')
    return "List items : " + str(Name) # Return all items in Name list  

if __name__ == '__main__':
    app.run(host='0.0.0.0',debug=True)


Sample cURL command:

curl –data “name=Sedat” –data “name=Steve” http://192.168.86.133:5000/api/example


Referances:
https://realpython.com/flask-connexion-rest-api/
https://www.jianshu.com/p/0b174567d85f

Bonus:
https://www.sedatozdemir.net/category/python/

Tarafından yazıldı
Sedat Ozdemir
Bir yorum bırak

Teşekkürler!

Bloğumu ziyaret ettiğiniz ve yazılarımı okuduğunuz için teşekkürler!