From acd2f0f9bd36cae3d860e3b0d73700db010e6d87 Mon Sep 17 00:00:00 2001
From: Will McCutchen <will@mccutch.org>
Date: Mon, 5 Sep 2016 21:29:00 -0500
Subject: [PATCH] Add /put /patch /delete handlers

---
 handlers.go | 2 +-
 main.go     | 9 ++++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/handlers.go b/handlers.go
index f0ab2ae..e36088e 100644
--- a/handlers.go
+++ b/handlers.go
@@ -44,7 +44,7 @@ func get(w http.ResponseWriter, r *http.Request) {
 	writeJSON(w, body, http.StatusOK)
 }
 
-func post(w http.ResponseWriter, r *http.Request) {
+func requestWithBody(w http.ResponseWriter, r *http.Request) {
 	args, err := url.ParseQuery(r.URL.RawQuery)
 	if err != nil {
 		http.Error(w, fmt.Sprintf("error parsing query params: %s", err), http.StatusBadRequest)
diff --git a/main.go b/main.go
index 891dfc6..afaf04a 100644
--- a/main.go
+++ b/main.go
@@ -11,13 +11,20 @@ const maxMemory = 1024*1024*5 + 1
 func app() http.Handler {
 	h := http.NewServeMux()
 	templateWrapper := withTemplates("templates/*.html")
+
 	h.HandleFunc("/", methods(templateWrapper(index), "GET"))
 	h.HandleFunc("/forms/post", methods(templateWrapper(formsPost), "GET"))
+
 	h.HandleFunc("/get", methods(get, "GET"))
-	h.HandleFunc("/post", methods(post, "POST"))
+	h.HandleFunc("/post", methods(requestWithBody, "POST"))
+	h.HandleFunc("/put", methods(requestWithBody, "PUT"))
+	h.HandleFunc("/patch", methods(requestWithBody, "PATCH"))
+	h.HandleFunc("/delete", methods(requestWithBody, "DELETE"))
+
 	h.HandleFunc("/ip", ip)
 	h.HandleFunc("/user-agent", userAgent)
 	h.HandleFunc("/headers", headers)
+
 	return logger(cors(h))
 }
 
-- 
GitLab