Document superhero storing and improve API response message

This commit is contained in:
2023-02-07 04:53:44 +00:00
parent fca4c76cf9
commit 21fb147017
2 changed files with 33 additions and 4 deletions

View File

@@ -39,9 +39,12 @@ The application can be configured via environment variables:
## API Documentation ## API Documentation
### GET /superheroes ### Get a list of superheroes
```http request
GET /superheroes
```
Returns a list of superheroes.
#### Parameters #### Parameters
@@ -50,7 +53,9 @@ Returns a list of superheroes.
#### Example #### Example
`GET /superheroes?superpowers=strength,flight&encrypted=true` ```http request
GET /superheroes?superpowers=strength,flight&encrypted=true
```
#### Result #### 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"
}
```

View File

@@ -146,7 +146,13 @@ func (r *Router) StoreSuperHero(w http.ResponseWriter, req *http.Request) {
// Return JSON // Return JSON
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated) 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 { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return