@@ -22,6 +22,7 @@ go get github.com/manyminds/api2go/jsonapi
2222## TOC
2323- [ Examples] ( #examples )
2424- [ Interfaces to implement] ( #interfaces-to-implement )
25+ - [ Responder] ( #responder )
2526 - [ EntityNamer] ( #entitynamer )
2627 - [ MarshalIdentifier] ( #marshalidentifier )
2728 - [ UnmarshalIdentifier] ( #unmarshalidentifier )
@@ -69,6 +70,19 @@ json ignore tag. Api2go will use the `GetID` method that you implemented for you
6970In order to use different internal names for elements, you can specify a jsonapi tag. The api will marshal results now with the name in the tag.
7071Create/Update/Delete works accordingly, but will fallback to the internal value as well if possible.
7172
73+ ### Responder
74+ ``` go
75+ type Responder interface {
76+ Metadata () map [string ]interface {}
77+ Result () interface {}
78+ StatusCode () int
79+ }
80+ ```
81+
82+ The Responder interface must be implemented if you are using our API. It
83+ contains everything that is needed for a response. You can see an example usage
84+ of it in our example project.
85+
7286### EntityNamer
7387``` go
7488type EntityNamer interface {
@@ -306,19 +320,19 @@ First, write an implementation of `api2go.CRUD`. You have to implement at least
306320``` go
307321type fixtureSource struct {}
308322
309- func (s *fixtureSource ) FindOne (ID string , r api2go .Request ) (interface {} , error ) {
323+ func (s *fixtureSource ) FindOne (ID string , r api2go .Request ) (Responder , error ) {
310324 // Return a single post by ID as Post
311325}
312326
313- func (s *fixtureSource ) Create (obj interface {}, r api2go .Request ) (string , error ) {
327+ func (s *fixtureSource ) Create (obj interface {}, r api2go .Request ) (Responder , err error ) {
314328 // Save the new Post in `obj` and return its ID.
315329}
316330
317- func (s *fixtureSource ) Delete (id string , r api2go .Request ) error {
331+ func (s *fixtureSource ) Delete (id string , r api2go .Request ) ( Responder , err error ) {
318332 // Delete a post
319333}
320334
321- func (s *fixtureSource ) Update (obj interface {}, r api2go .Request ) error {
335+ func (s *fixtureSource ) Update (obj interface {}, r api2go .Request ) ( Responder , err error ) {
322336 // Apply the new values in the Post in `obj`
323337}
324338```
@@ -329,11 +343,11 @@ interfaces:
329343``` go
330344type FindAll interface {
331345 // FindAll returns all objects
332- FindAll (req Request ) (interface {} , error )
346+ FindAll (req Request ) (Responder , error )
333347}
334348
335349type PaginatedFindAll interface {
336- PaginatedFindAll (req Request ) (obj interface {}, totalCount uint , err error )
350+ PaginatedFindAll (req Request ) (totalCount uint , response Responder , err error )
337351}
338352```
339353
@@ -523,7 +537,7 @@ query Paramter and only return comments that belong to it. In this example, retu
523537## Tests
524538
525539``` sh
526- go test
527- ginkgo # Alternative
528- ginkgo watch -notify # Watch for changes
540+ go test ./...
541+ ginkgo -r # Alternative
542+ ginkgo watch -r - notify # Watch for changes
529543```
0 commit comments