From 21fb147017b0519160d7d1e6f03a9aff3712cade Mon Sep 17 00:00:00 2001 From: Andriy Oblivantsev Date: Tue, 7 Feb 2023 04:53:44 +0000 Subject: [PATCH] Document superhero storing and improve API response message --- README.md | 29 ++++++++++++++++++++++++++--- api/router.go | 8 +++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 30f2d90..15fc2c1 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,12 @@ The application can be configured via environment variables: ## API Documentation -### GET /superheroes +### Get a list of superheroes + +```http request +GET /superheroes +``` -Returns a list of superheroes. #### Parameters @@ -50,7 +53,9 @@ Returns a list of superheroes. #### Example -`GET /superheroes?superpowers=strength,flight&encrypted=true` +```http request +GET /superheroes?superpowers=strength,flight&encrypted=true +``` #### Result @@ -84,3 +89,21 @@ Returns a list of superheroes. } ] ``` + +### Store superhero data + +```http request +PUT /superheroes + +{"name":"supermans","identity":{"firstName":"Kent","lastName":"Clark"},"superpowers":["flight","strength","invulnerability"],"birthday":"1977-04-18"} +``` + + +#### Result + +```json +{ + "message": "Superhero stored successfully.", + "status": "success" +} +``` diff --git a/api/router.go b/api/router.go index 37f1722..ebd0cbd 100644 --- a/api/router.go +++ b/api/router.go @@ -146,7 +146,13 @@ func (r *Router) StoreSuperHero(w http.ResponseWriter, req *http.Request) { // Return JSON w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusCreated) - _, err = w.Write([]byte(`{"status": "ok"}`)) + + // Response body + _, err = w.Write([]byte(`{ + "message": "Superhero stored successfully.", + "status": "success" + }`)) + if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return