Complete Guide on Rest API with Python and Flask

PHOTO EMBED

Thu Mar 03 2022 07:21:34 GMT+0000 (UTC)

Saved by @morristech #python

from flask import Flask
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
data = []
class People(Resource):
	def get(self):
		for x in data:
			if x['Data'] == name:
				return x
		return {'Data': None}
	def post(self, name):
		temp = {'Data': name}
		data.append(temp)
		return temp
	def delete(self):
		for ind, x in enumerate(data):
			if x['Data'] == name:
				temp = data.pop(ind)
				return {'Note': 'Deleted'}
api.add_resource(People, '/Name/')
if __name__ == '__main__':
	app.run(debug=True)
content_copyCOPY

https://www.analyticsvidhya.com/blog/2022/01/rest-api-with-python-and-flask/