Receiving a Response
After the REST API receives a request, it generates and sends a response. The response contains information about the resource requested, as well as any diagnostic information about the request itself. This includes whether the server received the request, how the server interpreted the request, and whether the server was actually able to fulfill the request.
Status Codes
HTTP status codes indicate the result of the REST API's attempt to process a request. If the server successfully processed the request, it returns status code 200 (OK). If the server was unable to process the request, it will return status code 500 (Internal Server Error).
HTTP status codes are fully defined by the Internet Engineering Task Force (IETF) in RFC 7231 Section 6.1.
Body
The body contains the response formatted in JSON.
For example, a successful request for an incident returns the following JSON object:
[
{
"Oid": 1,
"Status": "New",
"ItemID": "IR-0000001",
"Requester": 76,
"Summary": "Fix Printer",
"Priority": "1 - Critical",
"DueDate": "2016-05-01T23:59:00-06:00"
}
]
Example Code in C#
HttpWebResponse httpWebResponse = (System.Net.HttpWebResponse)webRequest.GetResponse();
//RESPONSE
HttpWebResponse httpWebResponse = (System.Net.HttpWebResponse)webRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream();
using (var streamReader = new StreamReader(responseStream))
{
IDictionary responseData = new Hashtable();
var result = JsonConvert.DeserializeObject(streamReader.ReadToEnd());
if (result != null)
{
foreach (JProperty prop in ((Newtonsoft.Json.Linq.JObject)result).Properties())
{
responseData[prop.Name] = ((Newtonsoft.Json.Linq.JValue)(prop.Value)).Value;
}
string sessionId = responseData["sessionId"].ToString());
string userId = responseData["userId"].ToString());
}
}