summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--handlers.go14
-rw-r--r--main.go34
2 files changed, 39 insertions, 9 deletions
diff --git a/handlers.go b/handlers.go
index 3998228..a44c9d8 100644
--- a/handlers.go
+++ b/handlers.go
@@ -64,6 +64,20 @@ func apiEndpointHandler(w http.ResponseWriter, r *http.Request) {
 
 }
 
+// handles POST for "/api/plain/users"
+func apiEndpointPOSTHandler(w http.ResponseWriter, r *http.Request) {
+	vars := mux.Vars(r)
+	format := vars["format"]
+	endpoint := vars["endpoint"]
+
+	w.Header().Set("Content-Type", htmlutf8)
+	n, err := w.Write([]byte(format + "/" + endpoint))
+	if err != nil || n == 0 {
+		log.Printf("Error writing to HTTP stream: %v\n", err)
+	}
+
+}
+
 // handles "/api/plain/tags"
 func apiTagsBaseHandler(w http.ResponseWriter, r *http.Request) {
 	vars := mux.Vars(r)
diff --git a/main.go b/main.go
index ef083dc..267c4ea 100644
--- a/main.go
+++ b/main.go
@@ -14,20 +14,36 @@ const getwtxt = "0.1"
 
 func main() {
 
-	// more precise path-based routing
-	index := mux.NewRouter()
+	index := mux.NewRouter().StrictSlash(true)
 	api := index.PathPrefix("/api").Subrouter()
 
 	// gorilla/mux makes path validation painless
-	index.HandleFunc("/", indexHandler)
-	index.HandleFunc("/api", apiBaseHandler)
-	api.HandleFunc("/", apiBaseHandler)
-	api.HandleFunc("/{format:(?:plain)}", apiFormatHandler)
+	index.Path("/").
+		Methods("GET").
+		HandlerFunc(indexHandler)
+	index.Path("/api").
+		Methods("GET").
+		HandlerFunc(apiBaseHandler)
+	api.Path("/").
+		Methods("GET").
+		HandlerFunc(apiBaseHandler)
+	api.Path("/{format:(?:plain)}").
+		Methods("GET").
+		HandlerFunc(apiFormatHandler)
 	api.Path("/{format:(?:plain)}/{endpoint:(?:mentions|users|tweets)}").
-		Queries("url", "{url}", "q", "{query}", "nickname", "{nickname}").
+		Methods("GET").
+		Queries("url", "{url}", "q", "{query}").
 		HandlerFunc(apiEndpointHandler)
-	api.HandleFunc("/{format:(?:plain)}/tags", apiTagsBaseHandler)
-	api.HandleFunc("/{format:(?:plain)}/tags/{tags:[a-zA-Z0-9]+}", apiTagsHandler)
+	api.Path("/{format:(?:plain)}/{endpoint:users}").
+		Methods("POST").
+		Queries("url", "{url}", "nickname", "{nickname}").
+		HandlerFunc(apiEndpointPOSTHandler)
+	api.Path("/{format:(?:plain)}/tags").
+		Methods("GET").
+		HandlerFunc(apiTagsBaseHandler)
+	api.Path("/{format:(?:plain)}/tags/{tags:[a-zA-Z0-9]+}").
+		Methods("GET").
+		HandlerFunc(apiTagsHandler)
 
 	// format the port for the http.Server object
 	portnum := fmt.Sprintf(":%v", confObj.port)