API documentation. Fixes #30
This commit is contained in:
parent
e9132a1193
commit
62443e984d
7
pages.go
7
pages.go
|
@ -35,6 +35,13 @@ func pasteHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
func apiDocHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||
err := Templates["api.html"].ExecuteWriter(pongo2.Context{}, w)
|
||||
if err != nil {
|
||||
oopsHandler(c, w, r, RespHTML, "")
|
||||
}
|
||||
}
|
||||
|
||||
func notFoundHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(404)
|
||||
err := Templates["404.html"].ExecuteWriter(pongo2.Context{}, w)
|
||||
|
|
|
@ -75,6 +75,7 @@ func setup() {
|
|||
}
|
||||
TemplateSet := pongo2.NewSet("templates", p2l)
|
||||
TemplateSet.Globals["sitename"] = Config.siteName
|
||||
TemplateSet.Globals["siteurl"] = Config.siteURL
|
||||
err = populateTemplatesMap(TemplateSet, Templates)
|
||||
if err != nil {
|
||||
log.Fatal("Error: could not load templates", err)
|
||||
|
@ -93,6 +94,8 @@ func setup() {
|
|||
goji.Get("/", indexHandler)
|
||||
goji.Get("/paste/", pasteHandler)
|
||||
goji.Get("/paste", http.RedirectHandler("/paste/", 301))
|
||||
goji.Get("/API/", apiDocHandler)
|
||||
goji.Get("/API", http.RedirectHandler("/API/", 301))
|
||||
|
||||
if Config.remoteUploads {
|
||||
goji.Get("/upload", uploadRemote)
|
||||
|
|
|
@ -44,6 +44,7 @@ func populateTemplatesMap(tSet *pongo2.TemplateSet, tMap map[string]*pongo2.Temp
|
|||
templates := []string{
|
||||
"index.html",
|
||||
"paste.html",
|
||||
"api.html",
|
||||
"404.html",
|
||||
"401.html",
|
||||
"oops.html",
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block head %}
|
||||
<link href="/static/css/github-markdown.css" rel="stylesheet" type="text/css">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="main">
|
||||
<div id='inner_content'>
|
||||
<div class="normal markdown-body">
|
||||
|
||||
<h2>API</h2>
|
||||
|
||||
<h3>Uploading a file</h3>
|
||||
|
||||
<p>To upload a file, make a PUT request to <code>{{ siteurl }}upload/</code> and you will get the url of your upload back.</p>
|
||||
|
||||
<p><strong>Optional headers with the request</strong></p>
|
||||
|
||||
<p>Randomize the filename<br/>
|
||||
<code>Linx-Randomize: yes</code></p>
|
||||
|
||||
<p>Specify a custom deletion key<br/>
|
||||
<code>Linx-Delete-Key: mysecret</code></p>
|
||||
|
||||
<p>Specify an expiration time (in seconds)<br/>
|
||||
<code>Linx-Expiry: 60</code></p>
|
||||
|
||||
<p>Get a json response<br/>
|
||||
<code>Accept: application/json</code></p>
|
||||
|
||||
<p>The json response will then contain:</p>
|
||||
|
||||
<blockquote>
|
||||
<p>“url”: the publicly available upload url<br/>
|
||||
“filename”: the (optionally generated) filename<br/>
|
||||
“delete_key”: the (optionally generated) deletion key,<br/>
|
||||
“expiry”: the unix timestamp at which the file will expire (0 if never)<br/>
|
||||
“size”: the size in bytes of the file<br/>
|
||||
“mimetype”: the guessed mimetype of the file<br/>
|
||||
“sha256sum”: the sha256sum of the file,</p>
|
||||
</blockquote>
|
||||
|
||||
<p><strong>Examples</strong></p>
|
||||
|
||||
<p>Uploading myphoto.jpg</p>
|
||||
|
||||
<pre><code>$ curl -T myphoto.jpg {{ siteurl }}upload/
|
||||
{{ siteurl }}myphoto.jpg</code></pre>
|
||||
|
||||
<p>Uploading myphoto.jpg with an expiry of 20 minutes</p>
|
||||
|
||||
<pre><code>$ curl -H "Linx-Expiry: 1200" -T myphoto.jpg {{ siteurl }}upload/
|
||||
{{ siteurl }}myphoto.jpg</code></pre>
|
||||
|
||||
<p>Uploading myphoto.jpg with a random filename and getting a json response:</p>
|
||||
|
||||
<pre><code>$ curl -H "Accept: application/json" -H "Linx-Randomize: yes" -T myphoto.jpg {{ siteurl }}/upload/
|
||||
{"delete_key":"...","expiry":"0","filename":"f34h4iu.jpg","mimetype":"image/jpeg",
|
||||
"sha256sum":"...","size":"...","url":"{{ steurl }}/f34h4iu.jpg"}</code></pre>
|
||||
|
||||
<h3>Deleting a file</h3>
|
||||
|
||||
<p>To delete a file you uploaded, make a DELETE request to <code>{{ siteurl }}yourfile.ext</code> with the delete key set as the <code>Linx-Delete-Key</code> header.</p>
|
||||
|
||||
<p><strong>Example</strong></p>
|
||||
|
||||
<p>To delete myphoto.jpg</p>
|
||||
|
||||
<pre><code>$ curl -H "Linx-Delete-Key: mysecret" -X DELETE {{ siteurl }}myphoto.jpg
|
||||
DELETED</code></pre>
|
||||
|
||||
<h3>Information about a file</h3>
|
||||
|
||||
<p>To retrieve information about a file, make a GET request the public url with <code>Accept: application/json</code> headers and you will receive a json response containing:</p>
|
||||
|
||||
<blockquote>
|
||||
<p>“url”: the publicly available upload url<br/>
|
||||
“filename”: the (optionally generated) filename<br/>
|
||||
“expiry”: the unix timestamp at which the file will expire (0 if never)<br/>
|
||||
“size”: the size in bytes of the file<br/>
|
||||
“mimetype”: the guessed mimetype of the file<br/>
|
||||
“sha256sum”: the sha256sum of the file,</p>
|
||||
</blockquote>
|
||||
|
||||
<p><strong>Example</strong></p>
|
||||
|
||||
<pre><code>$ curl -H "Accept: application/json" {{ siteurl }}/myphoto.jpg
|
||||
{"expiry":"0","filename":"myphoto.jpg","mimetype":"image/jpeg","sha256sum":"...","size":"..."}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -14,7 +14,8 @@
|
|||
<div id="header">
|
||||
<div id="navigation" class="right">
|
||||
<a href="/">Upload</a> |
|
||||
<a href="/paste/">Paste</a>
|
||||
<a href="/paste/">Paste</a> |
|
||||
<a href="/API/">API</a>
|
||||
</div>
|
||||
<h2><a href="/" title="{{ sitename }}">{{ sitename }}</a></h2>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue