The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 906 - File: showthread.php PHP 7.2.34 (Linux)
File Line Function
/showthread.php 906 errorHandler->error



Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


[How To] access the API via HTTP using curl
#1
Included in moOde is a command API accessible via HTTP and ssh.

Using ssh is pretty self-explanatory but accessing the API via HTTP may not be.

Yes, you can manually type commands like
  • http://moode/command/?cmd=play
    or
  • http://moode/command/?cmd=vol.sh up 2
into your browser address bar, but that's not easily scriptable. Besides, if your browser has to be open, you might as well use moOde's webUI.

Linux, macOS, and Windows 10 [1] now all include a command-line tool named curl (sometimes written in text as cURL). This is a classic "Swiss Army knife" tool with lots of options. With it, we can easily script HTTP-based commands to the moOde API.

You can read the curl man page, but here's some examples of its use with moOde to get you started.

Code:
curl -G http://moode/command/ -d "cmd=play"

curl -G http://moode/command/ -d "cmd=vol.sh up 2"


The -G option tells curl to send an HTTP GET request rather than a POST request. Essentially this causes the same HTTP transaction as the "?" in the http://moode/command/?cmd=... strings does in browsers.

The -d (or --data) option indicates the item following it is the request payload.

Be sure to use the correct hostname or IP for your moOde player.

Use and enjoy.

Regards,
Kent

[1] I don't own any Macs so I have to rely on what I read on the InterWeb™. I've used curl in both Linux and Windows 10 systems (in cmd.exe, Powershell, and, of course, any Linux installed in Windows Subsystem for Linux).
Reply


Messages In This Thread
[How To] access the API via HTTP using curl - by TheOldPresbyope - 04-05-2020, 08:38 PM

Forum Jump: