public JObject ToJSON() { var JSON = JSONObject.Create( new JProperty("status_code", StatusCode), StatusMessage.IsNotNullOrEmpty() ? new JProperty("status_message", StatusMessage) : null, AdditionalInformation.IsNotNullOrEmpty() ? new JProperty("additionalInformation", AdditionalInformation) : null, RequestId.HasValue ? new JProperty("requestId", RequestId.Value.ToString()) : null, CorrelationId.HasValue ? new JProperty("correlationId", CorrelationId.Value.ToString()) : null, new JProperty("timestamp", Timestamp.ToIso8601()) ); return(JSON); }
public HTTPResponse.Builder ToHTTPResponseBuilder() { if (!Timestamp.HasValue) { Timestamp = DateTime.UtcNow; } HTTPResponseBuilder.Server = Request.HTTPRequest.HTTPServer.DefaultServerName; HTTPResponseBuilder.Date = Timestamp.Value; HTTPResponseBuilder.AccessControlAllowOrigin = "*"; HTTPResponseBuilder.Connection = "close"; if (Request.HTTPRequest.HTTPMethod != HTTPMethod.OPTIONS) { HTTPResponseBuilder.ContentType = HTTPContentType.JSON_UTF8; if (HTTPResponseBuilder.Content == null) { HTTPResponseBuilder.Content = JSONObject.Create( Data != null ? new JProperty("data", Data) : null, new JProperty("status_code", StatusCode ?? 2000), StatusMessage.IsNotNullOrEmpty() ? new JProperty("status_message", StatusMessage) : null, AdditionalInformation.IsNotNullOrEmpty() ? new JProperty("additionalInformation", AdditionalInformation) : null, RequestId.HasValue ? new JProperty("requestId", RequestId.Value.ToString()) : null, CorrelationId.HasValue ? new JProperty("correlationId", CorrelationId.Value.ToString()) : null, new JProperty("timestamp", (Timestamp ?? DateTime.UtcNow).ToIso8601()) ).ToUTF8Bytes(); } } HTTPResponseBuilder.Set("X-Request-ID", Request.RequestId). Set("X-Correlation-ID", Request.CorrelationId); HTTPResponseBuilder.SubprotocolResponse = this; return(HTTPResponseBuilder); }