~linuxgoose/bocpress

ref: 1240aa09969f0449c2cd2cc6e0643c1723d0afeb bocpress/main/templates/main/api_docs.html -rw-r--r-- 5.8 KiB
1240aa09Jordan Robinson update wording 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
{% extends 'main/layout.html' %}

{% block title %}API{% endblock %}

{% block content %}
<main>
    <h1>API</h1>
    <p>
        We provide an API to allow programmatic updating of your blog.
    </p>

    <dl>
        <dt>API Key</dt>
        <dd>{{ request.user.api_key|default:"your-api-key" }}</dd>
    </dl>
    {% if request.user.is_authenticated %}
    <p>
        <a href="{% url 'api_reset' %}">Reset API key ยป</a>
    </p>
    {% endif %}

    <h2>Notes</h2>
    <ul>
        <li>
            Click here to <a href="{% url 'api_reset' %}">reset your API key</a>.
            This will invalidate the current API key and issue a new one.
        </li>
        <li>The API is available at <code>https://bocpress.co.uk/api/</code>.</li>
        <li>All API endpoints end with a trailing slash.</li>
        <li>
            <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type">Content type</a>
            <code>application/json</code> is expected.
        </li>
        <li>There is no rate limiting.</li>
    </ul>

    <hr>

    <h2>Authentication</h2>
    <p>
        We authenticate requests using the
        <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization">Authorization</a>
        HTTP header, using the <code>Bearer</code> scheme.
    </p>
    <pre><code>Authorization: Bearer {{ request.user.api_key|default:"your-api-key" }}</code></pre>

    <h2>POST /api/posts/</h2>
    <p>
        Create new post.
    </p>

    <strong>Parameters</strong>
    <ul>
        <li><code>title</code>: string [required]</li>
        <li><code>body</code>: string [optional]</li>
        <li><code>published_at</code>: string (ISO date eg. 2006-01-31) [optional]</li>
        <li><code>tags</code>: string [optional]</li>
    </ul>

    <strong>Request</strong>
    <pre><code>{
    "title": "New blog",
    "body": "## Why?\n\nEveryone wants a blog, right?",
    "published_at": "2020-09-21"
    "tags": "life, tech, coding",
}</code></pre>

    <strong>Response</strong>
    <pre><code>{
    "ok": true,
    "slug": "new-blog",
    "url": "{{ protocol }}//{{ request.user.username|default:"your-username" }}.{{ host }}/blog/new-blog/"
}</code></pre>

    <strong>curl</strong>
    <pre><code>$ 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/
</code></pre>

    <h2>GET /api/posts/&lt;post-slug&gt;/</h2>
    <p>
        Get single post.
    </p>

    <strong>Parameters</strong>
    <ul>
        <li><em>(no parameters)</em></li>
    </ul>

    <strong>Response</strong>
    <pre><code>{
    "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/"
}</code></pre>

    <strong>curl</strong>
    <pre><code>$ curl -X GET \
    -H 'Authorization: Bearer {{ request.user.api_key|default:"your-api-key" }}' \
    {{ protocol }}//{{ host }}/api/posts/new-blog/
</code></pre>

    <h2>PATCH /api/posts/&lt;post-slug&gt;/</h2>
    <p>
        Update existing post.
    </p>

    <strong>Parameters</strong>
    <ul>
        <li><code>title</code>: string [optional]</li>
        <li><code>slug</code>: string (slug; no spaces) [optional]</li>
        <li><code>body</code>: string [optional]</li>
        <li><code>published_at</code>: string (ISO date eg. 2006-01-31; or empty to unpublish) [optional]</li>
    </ul>

    <strong>Request</strong>
    <pre><code>{
    "title": "Updating my new blog",
    "slug": "updating-blog",
    "body": "Welcome back!"
    "published_at": "2020-09-21"
}</code></pre>

    <strong>Response</strong>
    <pre><code>{
    "ok": true,
    "slug": "updating-blog",
    "url": "{{ protocol }}//{{ request.user.username|default:"your-username" }}.{{ host }}/blog/updating-blog/"
}</code></pre>

    <strong>curl</strong>
    <pre><code>$ 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/
</code></pre>


    <h2>DELETE /api/posts/&lt;post-slug&gt;/</h2>
    <p>
        Delete post.
    </p>

    <strong>Parameters</strong>
    <ul>
        <li><em>(no parameters)</em></li>
    </ul>

    <strong>Response</strong>
    <pre><code>{
    "ok": true
}</code></pre>

    <strong>curl</strong>
    <pre><code>$ curl -X DELETE \
    -H 'Authorization: Bearer {{ request.user.api_key|default:"your-api-key" }}' \
    {{ protocol }}//{{ host }}/api/posts/introducing-my-new-blog/
</code></pre>


    <h2>GET /api/posts/</h2>
    <p>
        List all posts.
    </p>

    <strong>Parameters</strong>
    <ul>
        <li><em>(no parameters)</em></li>
    </ul>

    <strong>Response</strong>
    <pre><code>{
    "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/"
        }
    ]
}</code></pre>

    <strong>curl</strong>
    <pre><code>$ curl -X GET \
    -H 'Authorization: Bearer {{ request.user.api_key|default:"your-api-key" }}' \
    {{ protocol }}//{{ host }}/api/posts/
</code></pre>

    <div style="margin-top: 64px;"></div>
</main>
{% endblock content %}