summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-11-10 11:19:03 -0500
committerTucker Evans <tuckerevans24@gmail.com>2019-11-10 11:19:03 -0500
commit04b3defc449973ec06f731b443acebe64cc64362 (patch)
tree09c90853337b280d49d3e3380cf999e2524651af
parent10b17512d7afe3e04f1b8740acf158b171e910df (diff)
Fix responses sent to client
JSON is no longer output to stdout and actually sent to client
-rw-r--r--backend/main.go18
1 files changed, 8 insertions, 10 deletions
diff --git a/backend/main.go b/backend/main.go
index 3dd9d38..1ed188a 100644
--- a/backend/main.go
+++ b/backend/main.go
@@ -51,11 +51,10 @@ func RecipeList(w http.ResponseWriter, r *http.Request) {
}
resp.Data = append(resp.Data, APIDataIds{Ids: ids})
- output, err := json.MarshalIndent(resp, "", " ")
- if err != nil {
- fmt.Println("Error converting to JSON")
- } else {
- fmt.Println(string(output))
+ w.Header().Set("Content-Type", "application/json; charset=UTF-8")
+ w.WriteHeader(http.StatusOK)
+ if err := json.NewEncoder(w).Encode(resp); err != nil {
+ panic(err)
}
}
}
@@ -78,11 +77,10 @@ func SingleRecipe(w http.ResponseWriter, r *http.Request) {
}
resp.Data = append(resp.Data, APIDataRecipe{recipe})
- output, err := json.MarshalIndent(resp, "", " ")
- if err != nil {
- fmt.Println("Error converting to JSON")
- } else {
- fmt.Println(string(output))
+ w.Header().Set("Content-Type", "application/json; charset=UTF-8")
+ w.WriteHeader(http.StatusOK)
+ if err := json.NewEncoder(w).Encode(resp); err != nil {
+ panic(err)
}
} else if r.Method == "POST" {