I have a spring-boot application up and running, with actuator endpoints configured mainly the /shutdown endpoint. I've been shutting it down (previously) with ^C and now am shutting down with curl -XPOST https://address:port/shutdown. My question is how would I map a command like that to a javascript function so I can shutdown the application with the click of a button?
            Asked
            
        
        
            Active
            
        
            Viewed 9,565 times
        
    1
            
            
        
        j-money
        
- 509
 - 2
 - 9
 - 32
 
2 Answers
3
            
            
        There is no way to execute curl command using javascript function so better use AJAX.
See below threads.
Executing curl from Javascript?
https://stackoverflow.com/a/31179836/6572971
Otherwise you can use java code to make it shutdown like below.
        Alien
        
- 15,141
 - 6
 - 37
 - 57
 
2
            
            
        By using Fetch ?
const myPost = async (postBody) => {
  const rawResponse = await fetch('https://address:port/shutdown', {
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(postBody)
  });
  const response = await rawResponse.json();
  console.log(response);
);
        Ashley Davis
        
- 9,896
 - 7
 - 69
 - 87
 
        servatj
        
- 196
 - 2
 - 10