0

can someone tell me which requests method should i use if i want to do this in a mysql database.

This is the execute method that i want to do. It works fine locally but i want to make it into an API so i am using the requests method to do that.

texts = message.text.split('@')

produk_id = texts[1]
id_pembeli = texts[2]

sql.execute("SELECT p.* , b.* , t.* FROM produk p, pembeli b, transaksi t WHERE p.produk_id='{produk_id}' AND b.pembeli_id='{pembeli_id}' AND t.pembeli_id='{pembeli_id}'".format(produk_id=str(produk_id), pembeli_id=str(id_pembeli)))

hasil_sql = sql.fetchall()

So the code above will first get the input that the user inputted(produk_id and pembeli_id) and then i want to select 3 table where the produk_id and pembeli_id. So which requests method should i use?

Noneam
  • 1
  • 1
  • It’s a SELECT statement, fetching data - so of course this should use GET. – CBroe Apr 26 '21 at 12:13
  • Does this answer your question? [Which HTTP Method to Choose When Building Restful API](https://stackoverflow.com/questions/46800414/which-http-method-to-choose-when-building-restful-api) – CBroe Apr 26 '21 at 12:14
  • @CBroe So i should use GET? will using get still take the text that is inputted by the user? like in produk_id = texts[1] – Noneam Apr 26 '21 at 12:35
  • I have just read the link you sent me. I know that i should use GET but i am just unsure about will the GET method select the table where the produk_id and pembeli_id is the same as what the user inputtted. – Noneam Apr 26 '21 at 12:40
  • I don’t know what `texts = message.text.split('@')` is supposed to be, so I can’t tell you that for sure. But either way, python surely has ways to access parameters that were send via GET, and ways to access them if they were sent via POST - so your decision, which method to use, should not depend on what your current code can handle in the first place. You decide what the appropriate method is first, and then you modify your code second, if necessary. – CBroe Apr 26 '21 at 12:43
  • Okay, Will do Thanks for the help. – Noneam Apr 26 '21 at 13:28

0 Answers0