Daniel Winterstein
Daniel Winterstein

Reputation: 2556

Should I use JSend for wrapping json ajax responses, or is there a more standard standard?

I'm setting up a json-over-http service. The responses should have some meta-data, primarily for success/failure. That could be done via http headers, but putting it in the json is nicer (it makes the meta-data available even if some higher-up part of the client code has consumed the http response object).

Is there an emerging standard for this?

I'm aware of JSend, but it doesn't seem to have widepsread adoption.

JSend, in a nutshell, is:

{
status: "success"|"fail"|"error", 
message: String, // optional error message 
data: any, // the ajax payload
code: Number // optional numeric code for errors
}

Upvotes: 2

Views: 702

Answers (1)

Daniel Winterstein
Daniel Winterstein

Reputation: 2556

My conclusion is: JSend is the most widely adopted wrapper format for json responses, so that is the way to go.

Upvotes: 3

Related Questions