summaryrefslogtreecommitdiff
path: root/docs/src/Interfaces/Item.md
diff options
context:
space:
mode:
authorOllie Phillips <7113347+olliephillips@users.noreply.github.com>2019-08-01 16:48:22 +0100
committerGitHub <noreply@github.com>2019-08-01 16:48:22 +0100
commitf0472b990d7022e2022538d54286bd11ecfaa912 (patch)
tree7928413f9d392e0fb2b683225dc6a7bcc5804ef6 /docs/src/Interfaces/Item.md
parent3ef2dc0da5d39686da48ac90e8a8a2c6b861e549 (diff)
parent4beb78e420595eea405566741490b2aa2f5e1854 (diff)
Merge pull request #311 from ponzu-cms/ponzu-dev
Merging ponzu-dev to master as v0.11.0
Diffstat (limited to 'docs/src/Interfaces/Item.md')
-rw-r--r--docs/src/Interfaces/Item.md29
1 files changed, 27 insertions, 2 deletions
diff --git a/docs/src/Interfaces/Item.md b/docs/src/Interfaces/Item.md
index 00971aa..9f805b8 100644
--- a/docs/src/Interfaces/Item.md
+++ b/docs/src/Interfaces/Item.md
@@ -107,13 +107,16 @@ func (p *Post) Omit(res http.ResponseWriter, req *http.Request) ([]string, error
### [item.Hookable](https://godoc.org/github.com/ponzu-cms/ponzu/system/item#Hookable)
Hookable provides lifecycle hooks into the http handlers which manage Save, Delete,
-Approve, and Reject routines. All methods in its set take an
-`http.ResponseWriter, *http.Request` and return an `error`.
+Approve, Reject routines, and API response routines. All methods in its set take an
+`http.ResponseWriter, *http.Request` and return an `error`. Hooks which relate to the API response, additionally take data of type `[]byte`, and may provide a return of the same type.
##### Method Set
```go
type Hookable interface {
+ BeforeAPIResponse(http.ResponseWriter, *http.Request, []byte) ([]byte, error)
+ AfterAPIResponse(http.ResponseWriter, *http.Request, []byte) error
+
BeforeAPICreate(http.ResponseWriter, *http.Request) error
AfterAPICreate(http.ResponseWriter, *http.Request) error
@@ -155,6 +158,28 @@ type Hookable interface {
##### Implementations
+#### BeforeAPIResponse
+BeforeAPIResponse is called before content is sent over the Ponzu API, and
+provides an opportunity to modify the response data. If a non-nil `error` value
+is returned, a 500 Internal Server Error is sent instead of the response.
+
+```go
+func (p *Post) BeforeAPIResponse(res http.ResponseWriter, req *http.Request, data []byte) ([]byte, error) {
+ return data, nil
+}
+```
+
+#### AfterAPIResponse
+AfterAPIResponse is called after content is sent over the Ponzu API, whether
+modified or not. The sent response data is available to the hook. A non-nil
+`error` return will simply generate a log message.
+
+```go
+func (p *Post) AfterAPIResponse(res http.ResponseWriter, req *http.Request, data []byte) error {
+ return nil
+}
+```
+
#### BeforeAPICreate
BeforeAPICreate is called before an item is created via a 3rd-party client. If a
non-nil `error` value is returned, the item will not be created/saved.