ProjectArea51 URL Shortener
This is our short url/memo service which runs at a51.li.
An earlier incarnation got hacked by spammers so for the last few years this service has been locked down.
Please do not ask for access to this service as you'll almost certainly be declined. These instructions are here just incase I do allow external access to this service.
Calling the service
Access to any of the endpoints on this service requires an Authorization request header included with the API key included.
curl -H 'Authorization: {{key}}' http://api.area51.onl/shorturl/{{endpoint}}
Generating a unique ID
The genid endpoint generates a unique ID used by the service. This ID is unique so one generated by this endpoint will never be reused by another part of the service.
$ curl -H 'Authorization: {{key}}' http://api.area51.onl/shorturl/genid "nUarQuLd"
Generating a short URL
This endpoint generates a short URL and makes it available on a51.li.
To use you need to make a http POST request with the request body containing a JSON object with one key url which contains the url to shorten.
$curl -H 'Authorization: {{key}}' -d '{"url":"{{url}}"}' http://api.area51.onl/shorturl/shorten {"surl":"http://a51.li/nUarQuLd","token":"nUarQuLd","dest":"http://maidstoneweather.com/","type":"link"}
The returned JSON object describes the details of that URL
- dest
- The destination URL
- surl
- The shortened URL
- token
- The generated ID used in the shortened URL
- type
- Always link for results from this endpoint
Recipes
Shorten a url within a bash script
sudo apt-get install jq
This recipe will shorten a URL from within a bash script:
$ URL='http://area51.onl/' $ SURL=$(curl -s -H 'Authorization: {{key}}' \ -d "{\"url\":\"$URL\"}" \ http://api.area51.onl/shorturl/shorten |\ jq -r 'select(.surl!=null)|.surl') $ echo $SURL http://a51.li/nUafcFpK
The bash variable SURL will either contain a url or be empty if there was a failure.
Generating a note
This endpoint generates a note, consisting of a title and a body, displayed on lined paper
To use you need to make a http POST request with the request body containing a JSON object with optionally the title and the body of the note:
- title
- The title of the note
- body
- The note content
- fixed
- Optional, if present then a monospaced font is used for the note body
$curl -H 'Authorization: {{key}}' -d '{"title":"{{title}}","body":"{{body}}"}' http://api.area51.onl/shorturl/note {"type":"note","dest":"http://a51.li/nUyyi8qr","token":"nUyyi8qr","surl":"http://a51.li/nUyyi8qr","title":"Test2","date":"Wed, 26 Oct 2016 21:38:05 GMT"}
The returned JSON object describes the details of that URL
- date
- The date of the note
- dest
- The note URL
- surl
- The note URL
- title
- The note title
- token
- The generated ID used in the shortened URL
- type
- Always note for results from this endpoint
Recipes
Create a note of a file
sudo apt-get install jq
This recipe will generate a note on a51.li with a title from $TITLE and the content of the file $FILE:
$ URL='http://area51.onl/' $ SURL=$(curl -s -H 'Authorization: {{key}}' \ -d "{\"fixed\":true,\"title\":\"$TITLE\",\"body\":$(jq -R -s -c '.' $FILE)}" \ http://api.area51.onl/shorturl/note | jq -r 'select(.surl!=null)|.surl') $ echo $SURL http://a51.li/nUymE5Na