Contents
Since version 0.10 DL offers a “RESTful” HTTP API that allows inter-operation between other services and/or native programs easily.
Every request is gated through the “/rest.php” page (or simply “/rest”, depending on the configuration), which is directly on the root of the web service, for example:
https://dl.example.com/rest.php
Each action is directly appended to the URI space, followed by parameters (if any):
/rest/request[/parameters]
Every request must be performed via the appropriate HTTP method (either “GET” or “POST”), and must always include HTTP’s “Basic” authorization credentials.
The credentials must also be replicated in a second header “X-Authorization” (which follows the same syntax as a normal “Basic” authorization scheme).
“POST” requests are x-www-form-urlencoded and must also include:
The output of every request can be:
An HTTP error code only (400, 401, 500, etc).
An HTTP error code with a JSON-encoded message with an “error” term:
{"error":"error description"}
A successful HTTP status (200), with a JSON-encoded message (even if empty) containing the specific request output.
An “info” request returns the service defaults and statistics.
Since: 0.10
Request method: “GET”
Request parameters: None
Returned values:
Example request:
GET /rest/info HTTP/1.0 Host: dl.example.com Authorization: Basic dGVzdDp0ZXN0 X-Authorization: Basic dGVzdDp0ZXN0
Example answer:
HTTP/1.1 200 OK Content-Type: application/json
{ "version": "0.11", "url": "http:\/\/www.thregr.org\/~wavexx\/software\/dl\/", "masterpath": "http:\/\/dl.example.com\/", "maxsize": 209715200, "defaults": { "grant": { "total": 31536000 }, "ticket": { "total": 31536000, "lastdl": 2592000, "maxdl": 0 } } }
A “newticket” request creates a new ticket.
Since: 0.10
Request method: “POST”
Request parameters: None
POST “msg” object parameters:
auto: | use server’s defaults for ticket expiration |
---|---|
once: | same as ticket_maxdl=1 with server’s default ticket_total |
never: | same as ticket_total/ticket_lastdl/ticket_maxdl=0 |
custom: | requires explicit ticket_total/ticket_lastdl/ticket_maxdl |
POST “file” parameter:
Returned values:
A “newgrant” request creates a new grant.
Since: 0.13
Request method: “POST”
Request parameters: None
POST “msg” object parameters:
auto: | use server’s defaults for grant expiration |
---|---|
once: | same as grant_maxul=1 with server’s default grant_total |
never: | same as grant_total/grant_lastul/grant_maxul=0 |
custom: | requires explicit grant_total/grant_lastul/grant_maxul |
auto: | use server’s defaults for ticket expiration |
---|---|
once: | same as ticket_maxdl=1 with server’s default ticket_total |
never: | same as ticket_total/ticket_lastdl/ticket_maxdl=0 |
custom: | requires explicit ticket_total/ticket_lastdl/ticket_maxdl |
Returned values:
A “purgeticket” request deletes a ticket ID and its associated file, notifying the owner (if requested).
Since: 0.11
Request method: “POST”
Request parameters:
POST “msg” object parameters: None
Returned values: None
Example request:
POST /rest/purgeticket/c1e3c2e0b6d5d0f0ada292c081fc4c49 HTTP/1.0 Host: dl.example.com Authorization: Basic dGVzdDp0ZXN0 X-Authorization: Basic dGVzdDp0ZXN0 Content-Type: application/x-www-form-urlencoded msg={}
Example answer:
HTTP/1.1 200 OK Content-Type: application/json {}
curl can be used to easily fiddle with the REST API.
A minimal request to create a new ticket can be performed with the following command:
curl https://dl.example.com/rest.php/newticket \ -F file=@filename -F msg={} \ -H 'Authorization: Basic dGVzdDp0ZXN0' \ -H 'X-Authorization: Basic dGVzdDp0ZXN0'
@filename is a special curl syntax that specifies the path to the filename to be posted. The basic authorization data is provided manually, as it needs to be replicated in the non-standard header “X-Authorization” anyway (this is used as a secondary token to prevent CSRF). You can construct the authorization hash on the command-line as well with the following:
echo -n 'user:password' | base64
Please keep in mind command-line arguments are usually visible to other users running on the same system, potentially exposing your password.
A Python API, supporting both asynchronous/synchronous operations and progress support can be found in the client/dl-wx/dl.py file. The API is used both by dl-wx.py and dl-cli.py in the same directory.
A simpler stand-alone implementation which can be helpful for testing can be found at client/dl-cli.py.