Hubitat api to get response out of Hubitat

Can you please explain this a little more clearly?

If you just want a 'device' that sends a http network packet for 'on' and another for 'off', take a look at the Open Source HttpSwitch from the Hubitat Public GitHub Repository.

You could then have the computer with the serial attached switch listen for these packets and send the correct serial commands.

Or, you could use by HubDuino software if you want to serially connect your switch to an Arduino or ESP8266 microcontroller.