{% extends 'main/layout.html' %} {% block title %}API — Mataroa{% endblock %} {% block content %}

API

We provide an API to allow programmatic updating of one’s blog.

API Key
{{ request.user.api_key|default:"your-api-key" }}
{% if request.user.is_authenticated %}

Reset API key »

{% endif %}

Notes


Authentication

We authenticate requests using the Authorization HTTP header, using the Bearer scheme.

Authorization: Bearer {{ request.user.api_key|default:"your-api-key" }}

POST /api/posts/

Create new post.

Parameters Request
{
    "title": "New blog",
    "body": "## Why?\n\nEveryone wants a blog, right?",
    "published_at": "2020-09-21"
}
Response
{
    "ok": true,
    "slug": "new-blog",
    "url": "{{ protocol }}//{{ request.user.username|default:"your-username" }}.{{ host }}/blog/new-blog/"
}
curl
$ curl -X POST \
    -H 'Authorization: Bearer {{ request.user.api_key|default:"your-api-key" }}' \
    -d '{"title": "New blog", "body": "## Why?\n\nEveryone needs a blog, right?"}' \
    {{ protocol }}//{{ host }}/api/posts/

GET /api/posts/<post-slug>/

Get single post.

Parameters Response
{
    "ok": true,
    "slug": "new-blog",
    "title": "New blog",
    "body": "Welcome!"
    "published_at": "2020-09-21"
    "url": "{{ protocol }}//{{ request.user.username|default:"your-username" }}.{{ host }}/blog/new-blog/"
}
curl
$ curl -X GET \
    -H 'Authorization: Bearer {{ request.user.api_key|default:"your-api-key" }}' \
    {{ protocol }}//{{ host }}/api/posts/new-blog/

PATCH /api/posts/<post-slug>/

Update existing post.

Parameters Request
{
    "title": "Updating my new blog",
    "slug": "updating-blog",
    "body": "Welcome back!"
    "published_at": "2020-09-21"
}
Response
{
    "ok": true,
    "slug": "updating-blog",
    "url": "{{ protocol }}//{{ request.user.username|default:"your-username" }}.{{ host }}/blog/updating-blog/"
}
curl
$ curl -X PATCH \
    -H 'Authorization: Bearer {{ request.user.api_key|default:"your-api-key" }}' \
    -d '{"title": "Updating my new blog", "body": "Rethinking and rewriting."}' \
    {{ protocol }}//{{ host }}/api/posts/introducing-my-new-blog/

DELETE /api/posts/<post-slug>/

Delete post.

Parameters Response
{
    "ok": true
}
curl
$ curl -X DELETE \
    -H 'Authorization: Bearer {{ request.user.api_key|default:"your-api-key" }}' \
    {{ protocol }}//{{ host }}/api/posts/introducing-my-new-blog/

GET /api/posts/

List all posts.

Parameters Response
{
    "ok": true,
    "post_list": [
        {
            "title": "On life",
            "slug": "on-life",
            "body": "What is life?\n\nAn illusion, a shadow, a story.",
            "published_at": null,
            "url": "{{ protocol }}//{{ request.user.username|default:"your-username" }}.mataroa.blog/blog/on-life/"
        },
        {
            "title": "New blog",
            "slug": "new-blog",
            "body": "With health!",
            "published_at": "2020-10-19",
            "url": "{{ protocol }}//{{ request.user.username|default:"your-username" }}.mataroa.blog/blog/new-blog/"
        }
    ]
}
curl
$ curl -X GET \
    -H 'Authorization: Bearer {{ request.user.api_key|default:"your-api-key" }}' \
    {{ protocol }}//{{ host }}/api/posts/
{% endblock %}