So I have a api route similar to the one that is shown below. It takes an sql command and then executes it, then returns the value in json format. I want to do this when a entry is made in a javascript webpage. Is is something that is possible
@app.route('/api/getdata', methods = ['GET'])
def insert_restaurant():
getuser = "SELECT name FROM restaurants ORDER BY RAND() LIMIT 1;" # This statement witll return the random restaurant tha the users have entered
conn = create_connection("", "", "", "")
getting_users = execute_read_query(conn, getuser)
return jsonify(getting_users)
the way that I am learning the node js stuff is similar to this. when the form is filled out it will go to the website, search, and then return the output
app.post('/process_form', function(req, res){
// create a variable to hold the username parsed from the request body
var search = req.body.search
// Now we will use the token wiht the name that the user entered
// For this we will use the axios method to return the result
axios.get('https://itunes.apple.com/search?term='+search)
.then((response)=>{
var songlist = response.data.results;
console.log(songlist);
// Now we will execute the results in the page named thanks
res.render('pages/thanks.ejs', {
songlist: songlist,
search: search
});
});
});
How can I implement the first command so that it would execute like the second command? is what I am saying even making sense? I am just lost