Skip to content
Colin Harrington edited this page Oct 4, 2016 · 9 revisions

JSON API Notes

See http://jsonapi.org.

The Very Basics

JSONAPI Basics

Rendering JSONAPI

Rendering JSONAPI formatted items

Handling JSONAPI

Handling JSONAPI formatted data

Links

Support for top-level links including related associations see document links

{  
    "data":{  
        "type":"article",
        "id":"1",
        "attributes":{  
            "title":"Save the Gumbo",
            "version":0
        },
        "relationships":{  
            "author":{  
                "data":{  
                    "type":"person",
                    "id":"1"
                }
            }
        }
    },
    "links":{  
        "self":"/articles?id=1",
        "related":{  
            "href":"/people?id=1"
        }
    }
}

Errors

Error handling implemented via http://jsonapi.org/format/#errors

Server Errors:

{  
    "errors":[  
        {  
            "status":500,
            "title":"org.grails.web.errors.GrailsWrappedRuntimeException",
            "detail":null,
            "source":{  
                "stacktrace":[  
                    "146 | org.grails.web.errors.GrailsExceptionResolver.setStatus",
                    "89 | org.grails.web.errors.GrailsExceptionResolver.resolveException",
                    "1193 | org.springframework.web.servlet.DispatcherServlet.processHandlerException",
                    "1030 | org.springframework.web.servlet.DispatcherServlet.processDispatchResult",
                    "980 | org.springframework.web.servlet.DispatcherServlet.doDispatch",
                    "897 | org.springframework.web.servlet.DispatcherServlet.doService",
                    "970 | org.springframework.web.servlet.FrameworkServlet.processRequest",
                    "861 | org.springframework.web.servlet.FrameworkServlet.doGet",
                    "846 | org.springframework.web.servlet.FrameworkServlet.service",
                    "230 | org.apache.catalina.core.ApplicationFilterChain.internalDoFilter",
                    "165 | org.apache.catalina.core.ApplicationFilterChain.doFilter",
                    "52 | org.apache.tomcat.websocket.server.WsFilter.doFilter",
                    "192 | org.apache.catalina.core.ApplicationFilterChain.internalDoFilter",
                    "165 | org.apache.catalina.core.ApplicationFilterChain.doFilter",
                    "55 | org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal",
                    "107 | org.springframework.web.filter.OncePerRequestFilter.doFilter",
                    "192 | org.apache.catalina.core.ApplicationFilterChain.internalDoFilter",
                    "165 | org.apache.catalina.core.ApplicationFilterChain.doFilter",
                    "105 | org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal",
                    "107 | org.springframework.web.filter.OncePerRequestFilter.doFilter",
                    "192 | org.apache.catalina.core.ApplicationFilterChain.internalDoFilter",
                    "165 | org.apache.catalina.core.ApplicationFilterChain.doFilter",
                    "77 | org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal",
                    "107 | org.springframework.web.filter.OncePerRequestFilter.doFilter",
                    "192 | org.apache.catalina.core.ApplicationFilterChain.internalDoFilter",
                    "165 | org.apache.catalina.core.ApplicationFilterChain.doFilter",
                    "67 | org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal",
                    "107 | org.springframework.web.filter.OncePerRequestFilter.doFilter",
                    "192 | org.apache.catalina.core.ApplicationFilterChain.internalDoFilter",
                    "165 | org.apache.catalina.core.ApplicationFilterChain.doFilter",
                    "197 | org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal",
                    "107 | org.springframework.web.filter.OncePerRequestFilter.doFilter",
                    "192 | org.apache.catalina.core.ApplicationFilterChain.internalDoFilter",
                    "165 | org.apache.catalina.core.ApplicationFilterChain.doFilter",
                    "107 | org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal",
                    "107 | org.springframework.web.filter.OncePerRequestFilter.doFilter",
                    "192 | org.apache.catalina.core.ApplicationFilterChain.internalDoFilter",
                    "165 | org.apache.catalina.core.ApplicationFilterChain.doFilter",
                    "198 | org.apache.catalina.core.StandardWrapperValve.invoke",
                    "108 | org.apache.catalina.core.StandardContextValve.invoke",
                    "522 | org.apache.catalina.authenticator.AuthenticatorBase.invoke",
                    "140 | org.apache.catalina.core.StandardHostValve.invoke",
                    "79 | org.apache.catalina.valves.ErrorReportValve.invoke",
                    "87 | org.apache.catalina.core.StandardEngineValve.invoke",
                    "349 | org.apache.catalina.connector.CoyoteAdapter.service",
                    "1110 | org.apache.coyote.http11.Http11Processor.service",
                    "66 | org.apache.coyote.AbstractProcessorLight.process",
                    "785 | org.apache.coyote.AbstractProtocol$ConnectionHandler.process",
                    "1425 | org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun",
                    "49 | org.apache.tomcat.util.net.SocketProcessorBase.run",
                    "61 | org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run"
                ]
            }
        }
    ]
}

Validation Errors:

{
    "errors":[
        {
            "code":"blank",
            "detail":"Property [title] of class [class grails.example.Article] cannot be blank",
            "source":{
                "object":"grails.example.Article",
                "field":"title",
                "rejectedValue":"",
                "bindingError":false
            }
        },
        {
            "code":"nullable",
            "detail":"Property [author] of class [class grails.example.Article] cannot be null",
            "source":{
                "object":"grails.example.Article",
                "field":"author",
                "rejectedValue":null,
                "bindingError":false
            }
        }
    ]
}