Document superhero storing and improve API response message
This commit is contained in:
29
README.md
29
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"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user