Skip to content
This repository was archived by the owner on Sep 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ func CreateBlog(w http.ResponseWriter, r *http.Request) {

// ...save your blog...

w.WriteHeader(http.StatusCreated)
w.Header().Set("Content-Type", jsonapi.MediaType)
w.WriteHeader(http.StatusCreated)

if err := jsonapi.MarshalOnePayload(w, blog); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down Expand Up @@ -288,8 +288,9 @@ func ListBlogs(w http.ResponseWriter, r *http.Request) {
// but, for now
blogs := testBlogsForList()

w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", jsonapi.MediaType)
w.WriteHeader(http.StatusOK)

if err := jsonapi.MarshalManyPayload(w, blogs); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
Expand Down Expand Up @@ -325,8 +326,9 @@ func CreateBlogs(w http.ResponseWriter, r *http.Request) {
// ...save each of your blogs
}

w.WriteHeader(http.StatusCreated)
w.Header().Set("Content-Type", jsonapi.MediaType)
w.WriteHeader(http.StatusCreated)

if err := jsonapi.MarshalManyPayload(w, blogs); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
Expand Down
3 changes: 2 additions & 1 deletion examples/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ func (h *ExampleHandler) listBlogs(w http.ResponseWriter, r *http.Request) {
// but, for now
blogs := fixtureBlogsList()

w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", jsonapi.MediaType)
w.WriteHeader(http.StatusOK)

if err := jsonapiRuntime.MarshalManyPayload(w, blogs); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
Expand Down
2 changes: 1 addition & 1 deletion request.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ var (
//
// // ...do stuff with your blog...
//
// w.WriteHeader(201)
// w.Header().Set("Content-Type", jsonapi.MediaType)
// w.WriteHeader(201)
//
// if err := jsonapi.MarshalOnePayload(w, blog); err != nil {
// http.Error(w, err.Error(), 500)
Expand Down
3 changes: 2 additions & 1 deletion response.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ func MarshalManyPayloadWithoutIncluded(w io.Writer, models interface{}) error {
//
// blogs := testBlogsForList()
//
// w.WriteHeader(http.StatusOK)
// w.Header().Set("Content-Type", jsonapi.MediaType)
// w.WriteHeader(http.StatusOK)
//
// if err := jsonapi.MarshalManyPayload(w, blogs); err != nil {
// http.Error(w, err.Error(), http.StatusInternalServerError)
// }
Expand Down