summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-11-08 11:42:54 -0500
committerTucker Evans <tuckerevans24@gmail.com>2019-11-08 11:42:54 -0500
commit65464cb62f9853a38d74f8bc310c2f4b7c19e36b (patch)
tree039cafa180f997e25af0ed2955028f3cd2b6cd5e
parent30ea1d1313e5830456b49cd100906eb0c4f3efd0 (diff)
Add basic http routing
-rw-r--r--backend/main.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/backend/main.go b/backend/main.go
new file mode 100644
index 0000000..7b66e00
--- /dev/null
+++ b/backend/main.go
@@ -0,0 +1,29 @@
+package main
+
+import "fmt"
+import "net/http"
+
+func RecipeList(w http.ResponseWriter, r *http.Request) {
+ if r.Method == "GET" {
+ fmt.Printf("Return all recipe names...\n")
+ } else if r.Method == "POST" {
+ } else if r.Method == "DELETE" {
+ }
+}
+
+func HandleRecipe(w http.ResponseWriter, r *http.Request) {
+ name := r.URL.Path[len("/recipes/"):]
+ if r.Method == "GET" {
+ fmt.Printf("Return recipe \"%s\"...\n", name)
+ } else if r.Method == "POST" {
+ fmt.Printf("Create recipe \"%s\"...\n", name)
+ } else if r.Method == "DELETE" {
+ fmt.Printf("Delete recipe \"%s\"...\n", name)
+ }
+}
+
+func main() {
+ http.HandleFunc("/recipes", RecipeList)
+ http.HandleFunc("/recipes/", HandleRecipe)
+ http.ListenAndServe(":8888", nil)
+}