-
Notifications
You must be signed in to change notification settings - Fork 0
📡 API
snippets is accessed via a HTTP REST API.
A user object.
{
"username": "zekro",
"id": "5189b770-3c49-45a8-8ebc-f6d40772c371",
"timestamp": "2021-05-10T14:39:17.033443+00:00"
}
An extended User
object containing a masterkey
property returned on user creation.
{
"username": "zekro",
"id": "5189b770-3c49-45a8-8ebc-f6d40772c371",
"timestamp": "2021-05-10T14:39:17.033443+00:00",
"masterkey": "..."
}
Response object when exchanging a masterkey
against the API.
{
"token": "..."
}
A code snippet object.
{
"ident": "slUkuX",
"language": "golang",
"code": "package main\n\nimport ...",
"owner": {
"username": "zekro",
"id": "5189b770-3c49-45a8-8ebc-f6d40772c371",
"timestamp": "2021-05-10T14:39:17.033443+00:00"
},
"id": "afb8d6a3-0484-468e-85c3-b3c3938609e4",
"timestamp": "2021-05-30T14:23:22.978033+00:00"
}
Create a new user with the given username
.
Example:
> GET /users/zekro HTTP/2
The response of this request will look like following:
{
"username": "zekro",
"masterkey": "W8aoXaBtnYIS79sFtyuPfudYnBxR5bTKM9huATRNkqsO7dOj-WZa0ezk7SmypIaC3WjmtGXSdfJe56ymzNJUKmPNunIdB8ma-xubWfSbEErpyH7uEYZnn-uqK9cgNGKOF1QbqwfqK9ouCETJjvy99sOFKRTo1akc74n8HGP/7Pc_",
"id": "66685ee3-4886-47fc-93d2-38ed1eaecaf2",
"timestamp": "2022-01-04T10:50:10.9548948+00:00"
}
⚠️ ATTENTION
The returnedmasterkey
will never be returned from the API after initial account creation, so store it securely!
Exchange a masterkey
to retrieve an apikey
, which then must be used to authenticate requests against the API. The token has to be passed in the Authorization
header using the bearer
token type.
Example:
> POST /users/zekro/apitoken HTTP/2
> Authorization: bearer W8aoXaBtnYIS79sFtyuPfudYnBxR5bTKM9huATRNkqsO7dOj-WZa0ezk7SmypIaC3WjmtGXSdfJe56ymzNJUKmPNunIdB8ma-xubWfSbEErpyH7uEYZnn-uqK9cgNGKOF1QbqwfqK9ouCETJjvy99sOFKRTo1akc74n8HGP/7Pc_
The response of this request will look like following:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI3MWRlYTZiYi05NWU5LTRkN2MtOTRhZi05ODZjNzFkOWQ4YjIiLCJ1bmlxdWVfbmFtZSI6Inpla3JvZGV2ZWxvcG1lbnQiLCJuYmYiOjE2NDEyOTQxMzYsImV4cCI6MTY3MjgzMDEzNiwiaWF0IjoxNjQxMjk0MTM2LCJpc3MiOiJyYW5uYS1zbmlwcGV0cyJ9.-JN5evO0O7RjMUumYclA909B8wHYn38OfX39MAn1_U0"
}
Delete a user account. This requires authentication using the masterkey
passed as basic
token via the Authorization
header.
Example:
> DELETE /users/zekro HTTP/2
> Authorization: bearer W8aoXaBtnYIS79sFtyuPfudYnBxR5bTKM9huATRNkqsO7dOj-WZa0ezk7SmypIaC3WjmtGXSdfJe56ymzNJUKmPNunIdB8ma-xubWfSbEErpyH7uEYZnn-uqK9cgNGKOF1QbqwfqK9ouCETJjvy99sOFKRTo1akc74n8HGP/7Pc_
The response of this request will look like following:
204 No Content
Create a new snippet.
ℹ️ Info
The created snippet will be linked to the authenticated account. This also allows alternation and deletion by the authenticated user. A snippet can also be created anonymously.
Example:
> POST /snippets HTTP/2
> Content-Type: application/json
> Authorization: bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI3MWRlYTZiYi05NWU5LTRkN2MtOTRhZi05ODZjNzFkOWQ4YjIiLCJ1bmlxdWVfbmFtZSI6Inpla3JvZGV2ZWxvcG1lbnQiLCJuYmYiOjE2NDEyOTQxMzYsImV4cCI6MTY3MjgzMDEzNiwiaWF0IjoxNjQxMjk0MTM2LCJpc3MiOiJyYW5uYS1zbmlwcGV0cyJ9.-JN5evO0O7RjMUumYclA909B8wHYn38OfX39MAn1_U0
{
"code": "package main\n\nfunc main() {\n\tprintln(\"Hello world!\")\n}",
"language": "go"
}
The response of this request will look like following:
{
"id": "7ed9ec0c-76a8-40d0-bebf-e99c6af1bf87",
"ident": "aaQ0KR",
"language": "go",
"code": "package main\n\nfunc main() {\n\tprintln(\"Hello world!\")\n}",
"timestamp": "2022-01-04T11:40:23.8534821+00:00",
"owner": {
"username": "zekro",
"id": "66685ee3-4886-47fc-93d2-38ed1eaecaf2",
"timestamp": "2021-05-10T14:39:17.033443+00:00"
}
}
Get a snippet object by its ident
or id
.
Example:
> GET /snippets/aaQ0KR HTTP/2
The response of this request will look like following:
{
"id": "7ed9ec0c-76a8-40d0-bebf-e99c6af1bf87",
"ident": "aaQ0KR",
"language": "go",
"code": "package main\n\nfunc main() {\n\tprintln(\"Hello world!\")\n}",
"timestamp": "2022-01-04T11:40:23.8534821+00:00",
"owner": {
"username": "zekro",
"id": "66685ee3-4886-47fc-93d2-38ed1eaecaf2",
"timestamp": "2021-05-10T14:39:17.033443+00:00"
}
}
List all linked snippets of an authenticated user.
ℹ️ Info
The returned snippet objects do not contain the fieldscode
andowner
.
Example:
> GET /snippets HTTP/2
> Authorization: bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI3MWRlYTZiYi05NWU5LTRkN2MtOTRhZi05ODZjNzFkOWQ4YjIiLCJ1bmlxdWVfbmFtZSI6Inpla3JvZGV2ZWxvcG1lbnQiLCJuYmYiOjE2NDEyOTQxMzYsImV4cCI6MTY3MjgzMDEzNiwiaWF0IjoxNjQxMjk0MTM2LCJpc3MiOiJyYW5uYS1zbmlwcGV0cyJ9.-JN5evO0O7RjMUumYclA909B8wHYn38OfX39MAn1_U0
The response of this request will look like following:
[
{
"id": "7ed9ec0c-76a8-40d0-bebf-e99c6af1bf87",
"ident": "aaQ0KR",
"language": "go",
"timestamp": "2022-01-04T11:40:23.8534821+00:00"
}
]
Delete a snippet which is linked to a user by its ident
or id
.
Example:
> DELETE /snippets/aaQ0KR HTTP/2
> Authorization: bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI3MWRlYTZiYi05NWU5LTRkN2MtOTRhZi05ODZjNzFkOWQ4YjIiLCJ1bmlxdWVfbmFtZSI6Inpla3JvZGV2ZWxvcG1lbnQiLCJuYmYiOjE2NDEyOTQxMzYsImV4cCI6MTY3MjgzMDEzNiwiaWF0IjoxNjQxMjk0MTM2LCJpc3MiOiJyYW5uYS1zbmlwcGV0cyJ9.-JN5evO0O7RjMUumYclA909B8wHYn38OfX39MAn1_U0
The response of this request will look like following:
204 No Content