What is this?

This is a link shortener. A sort of a backend practice, but it should run 24/7/53/<While I pay for my VPS> after I finish writing it.

Documentation conventions

All documentation assumes that the server is running server.com on port 80 without https, and you are trying to shorten a link to example.com.

All (non-global) parameters are mandatory, unless marked with question mark ? sign.

PATH means part in url after the first slash: e.g. in link http://server.com/short, "short" is PATH, while URL means full shortened link.

API reference

The API follows this convention: everything is done through GET requests, client supplies all necessary parameters in URLencoded format. Whatever server returns depends on parameters; it may be application/json (for programmable API) OR text/html (to render in HTML)

Example request: http://ln.twistea.su/api/linkadd?url=https%3A%2F%2Fexample.com&format=html.
This request may return something like: <a href="http://server.com/DEADF00D">your link: DEADF00D</a>

Note: server may return json string like null or true: according to rfc-8259, this is valid json and clients have to handle this accordingly.

Errors are returned like this: {"error": description} (some endpoints may return null / false to indicate failure). Description may be any of the following:

Plese note that the HTTP return status for malformed request may be BAD_REQUEST (400), URI_TOO_LONG (414), NOT_FOUND (404) or INTERNAL_SERVER_ERROR (500)

Table 1. Global parameters (applicable to all endpoints)
Key Value Description Default
format json | html How to return the result of request. html should only be used to embed it in a web page. json
Table 2. Endpoints description
Endpoint Parameters Response object
key value
/api/linkadd url string: a link to be shortened {"url": "https://server.com/PATH"} | error
try? string: PATH to try to put link under
shoud match regex [a-zA-Z0-9]+, length ≤ 10
may work with length = 11, but not always
(if not occupied, WITHOUT https://server.com/)
/api/linkdel path string: PATH to delete the link from true | false
/api/linkget path string: PATH to get link info from {"url": "original url", created: int unix_timestamp}
OR null
/PATH Returns an HTML page with redirection message and returns 302 (HTTP_FOUND), with Location header set to shortened URL
/getargs Get an HTML page with a list of all parameters provided to the endpoint. Used for testing.

Examples of API usage:

This section is unfinished.