Make api more restful

This commit is contained in:
Eliot Whalan 2016-07-12 10:50:44 +10:00
parent 1ac4e9da64
commit a2503d4b98
3 changed files with 23 additions and 20 deletions

View File

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

View File

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

View File

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