Developer API
The Anchr.io backend provides a powerful REST API (even though not completely RESTful yet) to interact with the
server and do all stuff the UI can do too.
The intention is to encourage developers to make own applications based on the Anchr.io functionality.
The API supports resources shortlink, image and collection with the following
routes.
A Swagger API specification is also available.
Shortlinks
|
| Method / format |
Endpoint |
Parameters / request body |
| GET |
/api/shortlink/:id |
pass Accept: application/json header to get resource meta data or Accept: */* to execute the actual redirection |
| POSTjson |
/api/shortlink |
{ "url" : "http://your-destination.tld" } |
Images
|
| Method / format |
Endpoint |
Parameters / request body |
| GET |
/api/image/:id |
pass Accept: application/json header to get resource meta data or Accept: */* to get the actual image |
| POSTmultipart |
/api/image |
uploadFile=@yourFileObjectHere |
Collections
|
| Method / format |
Endpoint |
Parameters / request body |
| GET |
/api/collection |
Returns an array of all collections for the authenticated user. |
| POSTjson |
/api/collection |
{ "name" : "My new collection" } |
| GET |
/api/collection/:id |
|
| DELETE |
/api/collection/:id |
|
| GET |
/api/collection/:id/links |
Accepts page, pageSize and q as query parameters for filtering links. |
| POSTjson |
/api/collection/:id/links |
{ "url" : "http://duckduckgo.com", "description" : "Search engine" } |
| GET |
/api/collection/:id/links/:linkId |
|
| DELETE |
/api/collection/:id/links/:linkId |
|
| POSTjson |
/api/collection/:id/share |
Makes this collection publicly readable under {{getClientUrl()}}collection/:id |
Resource models
Shortlink
{
"_id" : "bW2oL"
"url" : "http://example.com",
"href" : "http://anchr.io/s/bW2oL"
}
Image
{
"_id" : "Re49P.jpg"
"created" : 1448702387366,
"href" : "http://anchr.io/i/Re49P.jpg"
}
Collection
{
"_id" : "cg32e"
"name" : "My collection",
"shared" : false,
"owner" : "465826a3011dab3814fc71et"
"links" : [
{
"url" : "http://duckduckgo.com",
"description" : "Search engine"
"date" : 1448702387366
}
]
}
Authentication / Authorization
To use the /collection endpoints users need to authenticate against the API. Authentication is based on
JSON web tokens (JWT) and works as follows, assuming that
a user account already exists:
-
Make a login request:
POST/api/auth/token with body
{ "email" : "theusers@emailadress.tld", "password" : "userpasswordinplaintext" }
-
Get the token from the response:
{ "token" : "thisisareplacementforaverylongtoken" }
-
Set the Authorization header in every request to an
/collection endpoint:
Authorization: Bearer thisisareplacementforaverylongtoken