-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
41 lines (31 loc) · 865 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import flask
import flask_restful
app = flask.Flask(__name__)
api = flask_restful.Api(app)
api_resource = flask_restful.Resource
data_json = {
"minuman":"aqua"
}
# mengatur resource url
class products(api_resource):
def get(self):
return data_json
todos = {}
class Todo(api_resource):
def get(self,todo_id):
return {todo_id: todos[todo_id]}
def put(self,todo_id):
todos[todo_id] = flask.request.form['data']
return {todo_id: todos[todo_id]}
# menambahkan resource api
api.add_resource(products, "/")
api.add_resource(Todo, "/<string:todo_id>")
# ambil semua isi variabel put
@app.route("/api", methods=['PUT'])
def isi_put():
# ambil json
data = flask.request.get_json()
data_json = flask.jsonify({"put variabel":data})
print(data_json)
if __name__ == "__main__":
app.run(debug=True)