Calling a REST API from a trigger or stored procedure in mysql?
Asked Answered
S

2

7

I want to call rest api in a POST method from a stored procedure or trigger in mysql server on windows.

How do I perform this solely with MySQL?

Seeker answered 7/11, 2016 at 16:46 Comment(1)
Unrelated: "Yes, you should". Err, no. This community has its rules and policies. You dumping a list of requirements does not constitute a valid question in the scope of this place.Gnash
S
9

You can use a mysql-udf-http and then create a trigger like this:

delimiter $$
CREATE TRIGGER upd_check BEFORE UPDATE ON account 
FOR EACH ROW 
  BEGIN 
    IF NEW.amount > 0 THEN 
      set @json = select json_object(account_id,amount) 
      select http_post('http://restservice.example.com/account/post',@json); 
    END IF; 
  END;$$ 

delimiter;
Swatch answered 14/9, 2019 at 16:45 Comment(0)
I
-7

Basically you can't. And if you could (thru the use of a UDF library) you shouldn't.

Mysql is a high performance db engine that you ought to respect for its core competencies. Other stakeholders and waiting for your query or transaction to wrap up, and they suffer while yours doesn't. It is not a webserver with callbacks from asynchronous calls. Triggers and stored procs need to get in and get out as they are often used in a Transactional setting.

Inedible answered 7/11, 2016 at 17:16 Comment(2)
If I want to do then how could I create and install UDF library in mysql server on windows.Seeker
It certainly can be done and it is up to the developer whether or not to do things "right", "by the book", etc. Don't limit yourself by imaginary limitations - we have enough real ones.Bobo

© 2022 - 2024 — McMap. All rights reserved.