Make api more restful

This commit is contained in:
Eliot Whalan 2016-07-12 10:50:44 +10:00
parent c8ecc0c312
commit 3cddbf7c90
No known key found for this signature in database
GPG Key ID: C0A42175139840D6
3 changed files with 23 additions and 20 deletions

View File

@ -29,7 +29,7 @@
<div class="page-header">
<h1>{{.Title}}</h1>
</div>
<form action="/save/redirect" method="post" class="form-horizontal">
<form action="/p/redirect" method="post" class="form-horizontal">
<fieldset>
<div class="well" style="padding-top: 10px;">
<div class="form-group is-empty" style="margin-top: 0px;">
@ -471,11 +471,13 @@
</fieldset>
</form>
<div class="well">
<code>$ &lt;command&gt; | curl -F 'p=&lt;-' https://p.pantsu.cat/save</code><br/>
<code>https://p.pantsu.cat/save/(XML|JSON|HTML)</code><br/>
<code>https://p.pantsu.cat/p/(PASTE)/(lang)</code><br/>
<code>https://p.pantsu.cat/del/(PASTE)/(DELKEY)</code><br/>
<code>pasteurl = urllib2.urlopen("https://p.pantsu.cat/save", "p="+ data).read()</code><br/>
<code>$ &lt;command&gt; | curl -X POST -F 'p=&lt;-' https://p.pantsu.cat/p</code><br/>
<code>POST https://p.pantsu.cat/p/(XML|JSON|HTML)</code><br/>
<code>GET: https://p.pantsu.cat/p/(PASTE)/(lang)</code><br/>
<code>GET: https://p.pantsu.cat/raw/(PASTE)</code><br/>
<code>GET: https://p.pantsu.cat/download/(PASTE)</code><br/>
<code>GET: https://p.pantsu.cat/clone/(PASTE)</code><br/>
<code>DEL: https://p.pantsu.cat/p/(PASTE)/(DELKEY)</code><br/>
<p>Source: <a href="https://github.com/ewhal/Pastebin">Github</a></p>
</div>
</div>

View File

@ -29,7 +29,7 @@
<div class="page-header">
<h1>Pantsu Paste</h1>
</div>
<form action="/save/redirect" method="post" class="form-horizontal">
<form action="/p/redirect" method="post" class="form-horizontal">
<fieldset>
<div class="well" style="padding-top: 10px; resize: both;">
<div class="form-group is-empty" style="margin-top: 0px;">
@ -465,11 +465,13 @@
</fieldset>
</form>
<div class="well">
<code>$ &lt;command&gt; | curl -F 'p=&lt;-' https://p.pantsu.cat/save</code><br/>
<code>https://p.pantsu.cat/save/(XML|JSON|HTML)</code><br/>
<code>https://p.pantsu.cat/p/(PASTE)/(lang)</code><br/>
<code>https://p.pantsu.cat/del/(PASTE)/(DELKEY)</code><br/>
<code>pasteurl = urllib2.urlopen("https://p.pantsu.cat/save", "p="+ data).read()</code><br/>
<code>$ &lt;command&gt; | curl -X POST -F 'p=&lt;-' https://p.pantsu.cat/p</code><br/>
<code>POST https://p.pantsu.cat/p/(XML|JSON|HTML)</code><br/>
<code>GET: https://p.pantsu.cat/p/(PASTE)/(lang)</code><br/>
<code>GET: https://p.pantsu.cat/raw/(PASTE)</code><br/>
<code>GET: https://p.pantsu.cat/download/(PASTE)</code><br/>
<code>GET: https://p.pantsu.cat/clone/(PASTE)</code><br/>
<code>DEL: https://p.pantsu.cat/p/(PASTE)/(DELKEY)</code><br/>
<p>Source: <a href="https://github.com/ewhal/Pastebin">Github</a></p>
</div>
</div>

View File

@ -381,14 +381,13 @@ func rootHandler(w http.ResponseWriter, r *http.Request) {
func main() {
router := mux.NewRouter()
router.HandleFunc("/p/{pasteId}", pasteHandler)
router.HandleFunc("/raw/{pasteId}", rawHandler)
router.HandleFunc("/p/{pasteId}/{lang}", pasteHandler)
router.HandleFunc("/clone/{pasteId}", cloneHandler)
router.HandleFunc("/download/{pasteId}", downloadHandler)
router.HandleFunc("/save", saveHandler)
router.HandleFunc("/save/{output}", saveHandler)
router.HandleFunc("/del/{pasteId}/{delKey}", delHandler)
router.HandleFunc("/p/{pasteId}", pasteHandler).Methods("GET")
router.HandleFunc("/raw/{pasteId}", rawHandler).Methods("GET")
router.HandleFunc("/p/{pasteId}/{lang}", pasteHandler).Methods("GET")
router.HandleFunc("/clone/{pasteId}", cloneHandler).Methods("GET")
router.HandleFunc("/download/{pasteId}", downloadHandler).Methods("GET")
router.HandleFunc("/p/{output}", saveHandler).Methods("POST")
router.HandleFunc("/p/{pasteId}/{delKey}", delHandler).Methods("DELETE")
router.HandleFunc("/", rootHandler)
err := http.ListenAndServe(PORT, router)
if err != nil {