GeezerVison is showing github.com — Create api-file-flask · sambapython/python@b808754
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboard +32Lines changed: 32 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +from flask import Flask, request |
| 2 | +from flask.ext.spi import status |
| 3 | +import json |
| 4 | + |
| 5 | +app = Flask(__name__) |
| 6 | + |
| 7 | +@app.route("/users",methods=['GET','POST','PUT','DELETE']) |
| 8 | +def index(): |
| 9 | + if request.method == "POST": |
| 10 | + data = request.json() |
| 11 | + # write post code here |
| 12 | + # return response |
| 13 | + return "context",status.HTTP_201_CREATED |
| 14 | + # read about status attribute |
| 15 | + if reques.method == "GET": |
| 16 | + filter = request.values |
| 17 | + # get the data from table using connction and filter objects |
| 18 | + # data should be in json format |
| 19 | + return json.dumps(data) |
| 20 | + if reques.method == "PUT": |
| 21 | + filter = request.values |
| 22 | + # write a modification code here |
| 23 | + return "context",status.HTTP_200_OK |
| 24 | + if reques.method == "DELETE": |
| 25 | + filter = request.values |
| 26 | + # get the data from table using connction and filter objects |
| 27 | + # write a delete code here |
| 28 | + return "context",status.HTTP_200_OK |
| 29 | + |
| 30 | + |
| 31 | +if __name__ == "__main__": |
| 32 | + app.run(debug=True, host="0.0.0.0") |