From 19bf52b5bdfbce5fd47bedb0c1f7494d590068ae Mon Sep 17 00:00:00 2001 From: Josh Brandoff Date: Fri, 12 Jun 2015 22:27:37 -0400 Subject: [PATCH] Add JSONAPI support to context --- context.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/context.go b/context.go index f5f0de4a..a493dbfc 100644 --- a/context.go +++ b/context.go @@ -331,6 +331,15 @@ func (c *Context) JSON(code int, obj interface{}) { } } +// Serializes the given struct as JSON into the response body. +// It also sets the Content-Type as "application/vnd.api+json". +func (c *Context) JSONAPI(code int, obj interface{}) { + c.writermem.WriteHeader(code) + if err := render.WriteJSONAPI(c.Writer, obj); err != nil { + c.renderError(err) + } +} + // Serializes the given struct as XML into the response body. // It also sets the Content-Type as "application/xml". func (c *Context) XML(code int, obj interface{}) {