~gitpocket/gitpocket

8
main
mainfeed-discovery
gitpocket/web/templates/api.tmpl -rw-r--r--1.5 KiB ViewLogBlameView rawPermalink 0064912a0e feat(api): serve a json twin of every page under /api with scoped tokens 6 hours ago
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
{{define "content"}}
{{$d := .Data}}
<h3>API</h3>
<p>Every page on this site has a JSON twin under <code>{{$d.Base}}</code>, so <code>/~you/project/issues/4</code> is read from <code>/api/~you/project/issues/4</code>. Send a token from <a href="/settings/tokens">settings</a> as <code>Authorization: Bearer gp_…</code> or as the password of HTTP basic auth. Lists answer <code>{items, total, next}</code> and take <code>?from=</code> and <code>?limit=</code>, errors answer <code>{status, error}</code>, and fetching this address without asking for HTML returns the same table as JSON.</p>
<pre>curl -H "Authorization: Bearer $TOKEN" {{$d.Base}}/me
curl -H "Authorization: Bearer $TOKEN" -X POST -d '{"title":"crash on empty input"}' {{$d.Base}}/~you/project/issues
curl -H "Authorization: Bearer $TOKEN" --data-binary @notes.txt '{{$d.Base}}/gists?name=notes.txt&amp;visibility=public'</pre>
<p class="muted">Needs: <code>none</code> is open to anyone, <code>user</code> takes any credential, <code>write</code> a token scoped <code>all</code>, <code>gist</code> a token scoped <code>all</code> or <code>gist</code>, <code>password</code> a password or a session and <code>admin</code> a site administrator.</p>
{{range $d.Groups}}<h4 class="rule">{{.Name}}</h4>
<div class="apiwrap"><table class="apiroutes">{{range .Routes}}<tr><td class="verb">{{.Method}}</td><td class="route"><code>{{.Path}}</code></td><td class="needs"><span class="tag">{{.Needs}}</span></td><td>{{.About}}</td></tr>{{end}}</table></div>
{{end}}
{{end}}