shiori/docs/API.md
Felipe Martin 6f19c12c95
Start working on new REST API. Refactor logic in domains. (#497)
* added 404 template

* added auth domain

* added embed file for frontend

* added base config and dependencies

* added basic new http server

* added separated server command

* updated go modules

* removed modd file

* Added shortcut to send internal server error response

* Added JWT support to Auth Domain

* Added JWT support to API

* docs: added comments to response struct

* naming

* inline returns

* updated dependencies

* production logger

* bookmarks endpoint

* reverted old views api path

* frontend for api v1

* proper 404 error (not working atm)

* use response

* removed 404 html

* server error handler

* login and basic auth

* adjusted session duration

* properly retrieve tags

* properly delete bookmark

* cleanup

* archiver domain

* debug routes

* bookmark routes

* expiration by parameter

* move to logrus

* logout

* frontend cache

* updated dependencies

* http: migrated to gin

* linted

* Added version command

* unit tests, docs

* response test utils and tests

* remove logout handler

* auth

* createtag

* improved http test utilities

* assert message equals

* Remove 1.19 from test matrix

* moved api to v1 folder

* docs: contribute docs

* updated makefile

* updated usage docs

* warn in server command

* updaed docs with shiori version command

* Updated documentation

* deps: update
2023-07-17 14:30:18 +01:00

5.7 KiB

This is a brief explanation of Shiori's API. For more examples you can import this collection in Postman.

⚠️ This is the documentation for the old API. This API is deprecated and will be removed in the future. Please refer and start migrating to the API v1 instead.

Auth

Log in

Most actions require a session id. For that, you'll need to log in using your username and password.

Request info Value
Endpoint /api/login
Method POST

Body:

{
	"username": "shiori",
	"password": "gopher",
	"remember": true,
	"owner": true
}

It will return your session ID in a JSON:

{
    "session": "YOUR_SESSION_ID",
    "account": {
        "id": 1,
        "username": "shiori",
        "owner": true
    }
}

Log out

Log out of a session ID.

Request info Value
Endpoint /api/logout
Method POST
X-Session-Id Header sessionId

Bookmarks

Get bookmarks

Gets the last 30 bookmarks (last page).

Request info Value
Endpoint /api/bookmarks
Method GET
X-Session-Id Header sessionId

Returns:

{
    "bookmarks": [
        {
            "id": 825,
            "url": "https://interesting_cool_article.com",
            "title": "Cool Interesting Article",
            "excerpt": "An interesting and cool article indeed!",
            "author": "",
            "public": 0,
            "modified": "2020-12-06 00:00:00",
            "imageURL": "",
            "hasContent": true,
            "hasArchive": true,
            "tags": [
                {
                    "id": 7,
                    "name": "TAG"
                }
            ],
            "createArchive": false
        },
    ],
    "maxPage": 19,
    "page": 1
}

Add bookmark

Add a bookmark. For some reason, Shiori ignores the provided title and excerpt, and instead fetches them automatically. Note the tag format, a regular JSON list will result in an error.

Request info Value
Endpoint /api/bookmarks
Method POST
X-Session-Id Header sessionId

Body:

{
	"url": "https://interesting_cool_article.com",
	"createArchive": true,
	"public": 1,
	"tags": [{"name": "Interesting"}, {"name": "Cool"}],
	"title": "Cool Interesting Article",
	"excerpt": "An interesting and cool article indeed!"
}

Returns:

{
    "id": 827,
    "url": "https://interesting_cool_article.com",
    "title": "TITLE",
    "excerpt": "EXCERPT",
    "author": "AUTHOR",
    "public": 1,
    "modified": "DATE",
    "html": "HTML",
    "imageURL": "/bookmark/827/thumb",
    "hasContent": false,
    "hasArchive": true,
    "tags": [
        {
             "name": "Interesting"
        },
        {
             "name": "Cool"
        }
    ],
    "createArchive": true
}

Edit bookmark

Modifies a bookmark, by ID.

Request info Value
Endpoint /api/bookmarks
Method PUT
X-Session-Id Header sessionId

Body:

{
    "id": 3,
    "url": "https://interesting_cool_article.com",
    "title": "Cool Interesting Article",
    "excerpt": "An interesting and cool article indeed!",
    "author": "AUTHOR",
    "public": 1,
    "modified": "2019-09-22 00:00:00",
    "imageURL": "/bookmark/3/thumb",
    "hasContent": false,
    "hasArchive": false,
    "tags": [],
    "createArchive": false
}

After providing the ID, provide the modified fields. The syntax is the same as adding.

Delete bookmark

Deletes a list of bookmarks, by their IDs.

Request info Value
Endpoint /api/bookmarks
Method DEL
X-Session-Id Header sessionId

Body:

[1, 2, 3]

Tags

Get tags

Gets the list of tags, their IDs and the number of entries that have those tags.

Request info Value
Endpoint /api/tags
Method GET
X-Session-Id Header sessionId

Returns:

[
    {
        "id": 1,
        "name": "Cool",
        "nBookmarks": 1
    },
    {
        "id": 2,
        "name": "Interesting",
        "nBookmarks": 1
    }

Rename tag

Renames a tag, provided its ID.

Request info Value
Endpoint /api/tags
Method PUT
X-Session-Id Header sessionId

Body:

{
    "id": 1,
    "name": "TAG_NEW_NAME"
}

Accounts

List accounts

Gets the list of all user accounts, their IDs, and whether or not they are owners.

Request info Value
Endpoint /api/accounts
Method GET
X-Session-Id Header sessionId

Returns:

[
    {
        "id": 1,
        "username": "shiori",
        "owner": true
    }
]

Create account

Creates a new user.

Request info Value
Endpoint /api/accounts
Method POST
X-Session-Id Header sessionId
Body:
{
	"username": "shiori2",
	"password": "gopher",
	"owner": false
}

Edit account

Changes an account's password or owner status.

Request info Value
Endpoint /api/accounts
Method PUT
X-Session-Id Header sessionId
Body:
{
	"username": "shiori",
	"oldPassword": "gopher",
	"newPassword": "gopher",
	"owner": true
}

Delete accounts

Deletes a list of users.

Request info Value
Endpoint /api/accounts
Method DEL
X-Session-Id Header sessionId

Body:

["shiori", "shiori2"]