termux / termux/termux-api

Idea/Question: REST-API

Open
#49 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
4.3k
Forks
920
PR merge metrics
No merged PRs in 30d

Description

I like to make/have termux-api available via REST, for example:

Android:

% termux-rest &

PC:

% curl 'http://192.168.2.100:8091/camera-photo?c=1'

retrieves JPEG direct

% curl http://192.168.2.100:8091/camera-info

retrieves JSON

etc. essentially http://x.x.x.x:port/(\w+)?(.+) -> termux-$1 $2 (with some proper argument parsing)

Question: what would be the easiest way (programming framework) to implement this lightweight http server providing the functionality?

I quickly coded (2hr) perl script which implements basic web-server which calls termux-* (with simple argument parsing) and takes output to return to http GET request, yet, it might be more suitable to use termux-api.c direct and put a small web-server into it, which connects to the internal API instead via termux-* -> termux-api -> am -> tcp.

I like to probe multiple android phones for battery info (actually the battery temperature is what I care about) and take photos via REST, turning Android smartphones into IoT devices.

My quick hack does this, accessing http://192.168.2.100:8091/ gives an overview of the services:

termux-rest (0.0.2) services:
   battery-status
   camera-info
   camera-photo: c=<...>
   location
   telephony-cellinfo
   telephony-deviceinfo
   tts-engines
   tts-speak: speak=<...>
   vibrate

with Content-Type: text/html, each service listed is a link.

and http://192.168.2.100:8091/battery-status:

{
  "health": "GOOD",
  "percentage": 97,
  "plugged": "UNPLUGGED",
  "status": "DISCHARGING",
  "temperature": 23.600000381469727
}

with Content-Type: application/json and CORS set so XHR JavaScript requests can be made.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the proposed termux-rest flow, the termux-* commands, and the referenced termux-api.c path. Define the endpoint, argument-parsing, output-format, and security requirements before deciding whether the server should invoke commands or connect to the internal API; done would mean an agreed design rather than the question's prototype.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, perl
Domain
api, mobile
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.