Skip to content
This repository was archived by the owner on Sep 4, 2025. It is now read-only.

Commit d8473fd

Browse files
committed
Updating README to reflect Marshal API changes.
1 parent 6d8fde6 commit d8473fd

File tree

1 file changed

+4
-60
lines changed

1 file changed

+4
-60
lines changed

README.md

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,13 @@ UnmarshalPayload(in io.Reader, model interface{})
206206

207207
Visit [godoc](http://godoc.org/github.com/google/jsonapi#UnmarshalPayload)
208208

209-
#### `MarshalOnePayload`
209+
#### `MarshalPayload`
210210

211211
```go
212-
MarshalOnePayload(w io.Writer, model interface{}) error
212+
MarshalPayload(w io.Writer, models interface{}) error
213213
```
214214

215-
Visit [godoc](http://godoc.org/github.com/google/jsonapi#MarshalOnePayload)
215+
Visit [godoc](http://godoc.org/github.com/google/jsonapi#MarshalPayload)
216216

217217
Writes a JSON API response, with related records sideloaded, into an
218218
`included` array. This method encodes a response for a single record
@@ -235,63 +235,7 @@ func CreateBlog(w http.ResponseWriter, r *http.Request) {
235235
w.Header().Set("Content-Type", jsonapi.MediaType)
236236
w.WriteHeader(http.StatusCreated)
237237

238-
if err := jsonapi.MarshalOnePayload(w, blog); err != nil {
239-
http.Error(w, err.Error(), http.StatusInternalServerError)
240-
}
241-
}
242-
```
243-
244-
### List Records Example
245-
246-
#### `MarshalManyPayload`
247-
248-
```go
249-
MarshalManyPayload(w io.Writer, models []interface{}) error
250-
```
251-
252-
Visit [godoc](http://godoc.org/github.com/google/jsonapi#MarshalManyPayload)
253-
254-
Takes an `io.Writer` and an slice of `interface{}`. Note, if you have a
255-
type safe array of your structs, like,
256-
257-
```go
258-
var blogs []*Blog
259-
```
260-
261-
you will need to iterate over the slice of `Blog` pointers and append
262-
them to an interface array, like,
263-
264-
```go
265-
blogInterface := make([]interface{}, len(blogs))
266-
267-
for i, blog := range blogs {
268-
blogInterface[i] = blog
269-
}
270-
```
271-
272-
Alternatively, you can insert your `Blog`s into a slice of `interface{}`
273-
the first time. For example when you fetch the `Blog`s from the db
274-
`append` them to an `[]interface{}` rather than a `[]*Blog`. So your
275-
method signature to reach into your data store may look something like
276-
this,
277-
278-
```go
279-
func FetchBlogs() ([]interface{}, error)
280-
```
281-
282-
##### Handler Example Code
283-
284-
```go
285-
func ListBlogs(w http.ResponseWriter, r *http.Request) {
286-
// ...fetch your blogs, filter, offset, limit, etc...
287-
288-
// but, for now
289-
blogs := testBlogsForList()
290-
291-
w.Header().Set("Content-Type", jsonapi.MediaType)
292-
w.WriteHeader(http.StatusOK)
293-
294-
if err := jsonapi.MarshalPayload(w, blogs); err != nil {
238+
if err := jsonapi.MarshalPayload(w, blog); err != nil {
295239
http.Error(w, err.Error(), http.StatusInternalServerError)
296240
}
297241
}

0 commit comments

Comments
 (0)