Skip to content

Instantly share code, notes, and snippets.

@MkDierz
Last active September 2, 2021 03:46
Show Gist options
  • Save MkDierz/9a0a47637a1095ac193ad79101f3e4bf to your computer and use it in GitHub Desktop.
Save MkDierz/9a0a47637a1095ac193ad79101f3e4bf to your computer and use it in GitHub Desktop.
basic axios example
from flask import Flask, request
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class data_api(Resource):
def post(self):
json_data = request.get_json()
print(json_data['data'])
print(json_data['select'])
#json_data berisi data dari post
api.add_resource(data_api, '/api/v1', endpoint='v1')
<input type="text" id="input" >
<select id="select">
<option value="str">String</option>
<option value="int">Interger</option>
<option value="bool">Boolean</option>
<option value="float">Decimal</option>
</select>
<button onclick="pushData()">submit</button>
var input = document.getElementById("input");
var toggle = document.getElementById("toogle");
function pushData() {
if (input.value) {
axios
.post("/api/v1", {
data: input.value,
select: select.value,
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment