Chapter 6. JSON Documents

Table of Contents

Response: Simple Document
Response: Collection Document
Request: Update Document

Response: Simple Document

This document is used in responses that contain no data, just a boolean status and a message. On success it might look like this:

HTTP/1.1 200 OK
Content-Type: application/json

{
   "success" : true,
   "message" : "all is good"
} 

On failure it might look like this:

HTTP/1.1 500 Server error
Content-Type: application/json    

{
   "success" : false,
   "message" : "Database connection failure"
} 

Response: Collection Document

A document that passes the data from the server to the client. This is the main representation of data in LinkRest.

HTTP/1.1 200 OK
Content-Type: application/json

{
   "data" : [
      { "id" : 5, "name": "A" },
      { "id" : 8, "name": "B" }
   ],
   "total" : 2
}

"data" array contains entity objects. Implicit entity model defines what attributes and relationships (collectively - "properties") each object has. A subset of properties showing in the collection document is a defined by a combination of server-side constraints and client request control parameters. Each object in the data array may contain related objects, those in turn may contain their related objects, with no limit on the depth of nesting.

"total" is a number of objects one would see in the collection if there was no pagination. If pagination is in use (see Pagination), the total may be greater than the number of visible objects in the "data" array. Otherwise it is equal to the size of "data".

Request: Update Document

Update Document is sent from the client to the server to modify an entity collection. It is a Collection document stripped down to its "data" section. There are two flavors - a single object and an array of objects:

{ "id" : 5, "name": "X" } 
[
   { "id" : 5, "name": "X" },
   { "id" : 8, "name": "Y" }
]