From a2503d4b9882a7fd28897fdf0d6cde327f8856b6 Mon Sep 17 00:00:00 2001 From: Eliot Whalan Date: Tue, 12 Jul 2016 10:50:44 +1000 Subject: [PATCH] Make api more restful --- assets/clone.html | 14 ++++++++------ assets/index.html | 14 ++++++++------ pastebin.go | 15 +++++++-------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/assets/clone.html b/assets/clone.html index 6bf2980..f211b74 100644 --- a/assets/clone.html +++ b/assets/clone.html @@ -29,7 +29,7 @@ -
+
@@ -471,11 +471,13 @@
- $ <command> | curl -F 'p=<-' https://p.pantsu.cat/save
- https://p.pantsu.cat/save/(XML|JSON|HTML)
- https://p.pantsu.cat/p/(PASTE)/(lang)
- https://p.pantsu.cat/del/(PASTE)/(DELKEY)
- pasteurl = urllib2.urlopen("https://p.pantsu.cat/save", "p="+ data).read()
+ $ <command> | curl -X POST -F 'p=<-' https://p.pantsu.cat/p
+ POST https://p.pantsu.cat/p/(XML|JSON|HTML)
+ GET: https://p.pantsu.cat/p/(PASTE)/(lang)
+ GET: https://p.pantsu.cat/raw/(PASTE)
+ GET: https://p.pantsu.cat/download/(PASTE)
+ GET: https://p.pantsu.cat/clone/(PASTE)
+ DEL: https://p.pantsu.cat/p/(PASTE)/(DELKEY)

Source: Github

diff --git a/assets/index.html b/assets/index.html index d3eee56..0b661a3 100644 --- a/assets/index.html +++ b/assets/index.html @@ -29,7 +29,7 @@ -
+
@@ -465,11 +465,13 @@
- $ <command> | curl -F 'p=<-' https://p.pantsu.cat/save
- https://p.pantsu.cat/save/(XML|JSON|HTML)
- https://p.pantsu.cat/p/(PASTE)/(lang)
- https://p.pantsu.cat/del/(PASTE)/(DELKEY)
- pasteurl = urllib2.urlopen("https://p.pantsu.cat/save", "p="+ data).read()
+ $ <command> | curl -X POST -F 'p=<-' https://p.pantsu.cat/p
+ POST https://p.pantsu.cat/p/(XML|JSON|HTML)
+ GET: https://p.pantsu.cat/p/(PASTE)/(lang)
+ GET: https://p.pantsu.cat/raw/(PASTE)
+ GET: https://p.pantsu.cat/download/(PASTE)
+ GET: https://p.pantsu.cat/clone/(PASTE)
+ DEL: https://p.pantsu.cat/p/(PASTE)/(DELKEY)

Source: Github

diff --git a/pastebin.go b/pastebin.go index e8c9bd6..be704d9 100644 --- a/pastebin.go +++ b/pastebin.go @@ -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 {