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
#2
Great, thanks. Is there a list of commands available somewhere?

I can confirm, BTW, that it works fine from a Mac.
Reply
#3
(04-05-2020, 09:31 PM)Coustard Wrote: Great, thanks. Is there a list of commands available somewhere?

I can confirm, BTW, that it works fine from a Mac.

Currently, the -d "cmd=..." construct works with 
  • the commands available to mpc (execute 'mpc help' from the command line on a moOde player to see them), used as -d "cmd=play", etc.

  • vol.sh commands (execute '/var/www/vol.sh --help' from the command line on a moOde player to see them), used as  -d "cmd=vol.sh up 5", etc. [1]
In the upcoming moOde 6.5.0 Tim is introducing a new library update command libupd-submit.php which can also be used.

Thanks for checking macOS.

Regards,
Kent

[1] A strict reading of the output from /var/www/vol.sh --help indicates the verb up|dn|mute|restore should be preceded by a minus sign. Turns out it accepts the verbs with or without the preceding minus sign.
Reply
#4
Very cool. Thanks.
Reply


Forum Jump: