Skip to content

Commit

Permalink
Response of senile endpoint from string to JSON'ed QuoteType, add README
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno.chavez committed Sep 17, 2018
1 parent 6f9cf44 commit 8526dd6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,34 @@ HTTP/1.1 200 OK
Allow: GET,OPTIONS
```

### /senile:

#### GET:

Responds with a JSON body with a random quote in it.

```
HTTP/1.1 200 OK
Content-Type: application/json
Date: Mon, 04 Jun 2018 09:46:36 GMT
Content-Length: 134
{
"quote": "invention! A spark without kindling is a goal without hope.",
"uuid": "00000000-0000-0000-0000-000000000000",
"score": 0
}
```

#### OPTIONS:

Responds with a header where it shows the available type request for that route
```
HTTP/1.1 200 OK
Allow: GET,OPTIONS
```


### /one/{uuid}:

#### GET:
Expand Down
4 changes: 3 additions & 1 deletion handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,10 @@ func SenileHandler(w http.ResponseWriter, r *http.Request) {
quote = stringModifier(quoteArray1, quoteArray)
}

joinedQuote := database.QuoteType{Quote: quote}
marshaledData, _ := json.MarshalIndent(joinedQuote, "", "")
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(quote))
w.Write(marshaledData)

case "OPTIONS":
w.Header().Set("Allow", "GET,OPTIONS")
Expand Down

0 comments on commit 8526dd6

Please sign in to comment.