Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

RestfulAPI

Preston edited this page Jan 3, 2020 · 1 revision

Restful API

Most of the common actions can be controlled over the restful API.

The Restful API can be access via both the trusted port (defined by arg --rest-api or the regular web port with authtication.)

Adding torrents

Add by a remote file

  • POST /api/url
    curl --data "http://file-of-a-remote-torrent-url/file.torrent" "http://localhost:3001/api/url"

Add by uploading a torrent file.

  • POST /api/torrentfile
curl --data-binary @my.torrent "http://localhost:3001/api/torrentfile"

Add by a magnet link.

  • POST /api/magnet
    curl --data "magnet:?xt=urn:btih:..." "http://localhost:3001/api/magnet"

Get Torrent Info

  • GET /api/torrents
  • GET /api/torrent/abcd123456abcd123456abcd123456abcd123456

eg: http http://localhost:3001/api/torrents

List the details of the torrents that are actives. /api/torrents lists all, while /api/torrent/... gets one of them.

{
    "abcd123456abcd123456abcd123456abcd123456": {
        "AddedAt": "2020-01-03T16:40:01.88092268+08:00",
        "Done": false,
        "DoneCmdCalled": false,
        "DownloadRate": 944601.7,
        "Downloaded": 2834432,
        "Files": [
            {
                "Completed": 0,
                "Done": false,
                "DoneCmdCalled": false,
                "Path": "NameOfTheFile.mp4",
                "Percent": 0,
                "Size": 722847513,
                "Started": true
            }
        ],
        "InfoHash": "abcd123456abcd123456abcd123456abcd123456",
        "Loaded": true,
        "Magnet": "magnet:?xt=urn:btih:...",
        "Name": "NameOfTheTorrent",
        "Percent": 0.09,
        "SeedRatio": 0.0028273743,
        "Size": 2927978404,
        "Started": true,
        "StartedAt": "2020-01-03T16:40:02.383222715+08:00",
        "Stats": {
...........omited, see https://github.com/anacrolix/torrent/blob/master/conn_stats.go
        },
        "UploadRate": 0,
        "Uploaded": 0
    }
}

Get downloaded file info

  • GET /api/files

eg: http http://localhost:3001/api/files

List the files in the download directory. It's a nested structure of directory and files.

{
    "Children": [
        {
            "Children": [
                {
                    "Children": null,
                    "Modified": "2020-01-03T16:40:13.60421924+08:00",
                    "Name": "NameOfTheFile1.mp4",
                    "Size": 34224359
                }
            ],
            "Modified": "2020-01-03T16:40:09.248219284+08:00",
            "Name": "NameOfTheDir",
            "Size": 883443750
        }
    ],
    "Modified": "2020-01-03T16:40:03.124619355+08:00",
    "Name": "downloads",
    "Size": 883443750
}

Start/Stop/Delete a torrent task

  • POST /api/torrent
    HASH=abcd123456abcd123456abcd123456abcd123456
    # to start the task
    curl --data "start:${HASH}" "http://localhost:3001/api/torrent"

    # to stop the task
    curl --data "stop:${HASH}" "http://localhost:3001/api/torrent"

    # to remove the task
    curl --data "delete:${HASH}" "http://localhost:3001/api/torrent"

Start/Stop a file in a task

  • POST /api/file
    HASH=abcd123456abcd123456abcd123456abcd123456
    # to start the file
    curl --data "start:${HASH}:NameOfTheFile1.mp4" "http://localhost:3001/api/file"

    # to stop the file
    curl --data "stop:${HASH}:NameOfTheFile1.mp4" "http://localhost:3001/api/file"

Get System info

  • GET /api/stat
{
    "Runtime": "1.13.5",
    "System": {
        "cpu": 1.7025538307471353,
        "diskFree": 20868198400,
        "diskUsedPercent": 67.75702723749691,
        "goMemory": 5348720,
        "goRoutines": 304,
        "memUsedPercent": 18.995308053990264,
        "set": true
    },
    "Title": "SimpleTorrent",
    "Uptime": "2020-01-03T17:03:45.829239678+08:00",
    "Version": "1.1.4-4-gbe13cee"
}

Change of config

  • POST /api/configure
curl --data-binary @newconfig.json "http://localhost:3001/api/configure"