Application Packaging Standard

Last updated 18-Mar-2019

HTTP Responses

Response Groups

The following HTTP responses are used in the APS Protocol:

Code Explanation
200 OK Success, data returned
201 Created Success, a new resource created
204 No Content Success, no data returned
206 Partial Content Success, partial data returned

More details on HTTP/1.1 responses are available at RFC-2616-10.

When interacting with application endpoints, the APS controller expects the following response codes depending on the operation.

Note

Any response code different from expected is considered as a failure. In this case, the APS controller forwards the response to the initiator of the operation.

Operation Request operation Response code Description
provision POST
200 OK
201 CREATED
202 ACCEPTED
204 NO_CONTENT
Resource created, properties returned
Resource created, properties returned
Operation in progress, async phase is needed
Resource created, no properties returned
unprovision DELETE
200 OK
204 NO_CONTENT
405 METHOD_NOT_ALLOWED
Resource deleted, no content returned
Resource deleted, no content returned
Method not allowed for the specified URI
configure PUT
200 OK
204 NO_CONTENT
Resource updated, properties returned
Resource updated, no properties returned
upgrade POST
200 OK
204 NO_CONTENT
Service upgraded, content returned
Service upgraded, no content returned
notify POST
200 OK
204 NO_CONTENT
Event notification accepted
Event notification accepted
link POST
200 OK
204 NO_CONTENT
404 NOT_FOUND
405 METHOD_NOT_ALLOWED
501 NOT_IMPLEMENTED
Link established
Link established
Failure for unknown URI or unknown reasons
Method not allowed for the specified URI
Functionality not supported
unlink DELETE
200 OK
204 NO_CONTENT
404 NOT_FOUND
405 METHOD_NOT_ALLOWED
501 NOT_IMPLEMENTED
Link deleted
Link deleted
Failure for unknown URI or unknown reasons
Method not allowed for the specified URI
Functionality not supported
retrieve GET 200 OK Resource properties, including Counters usage, are returned
get Default values GET
200 OK
204 NO_CONTENT
404 NOT_FOUND
405 METHOD_NOT_ALLOWED
501 NOT_IMPLEMENTED
Properties with default values are returned
No content returned
Failure for unknown URI or unknown reasons
Method not allowed for the specified URI
Functionality not supported
get Configurations GET
200 OK
204 NO_CONTENT
404 NOT_FOUND
405 METHOD_NOT_ALLOWED
501 NOT_IMPLEMENTED
Environment configuration returned
No content returned
Failure for unknown URI or unknown reasons
Method not allowed for the specified URI
Functionality not supported

Below is a detailed description of each HTTP response.

Success Responses

200 OK

The request has succeeded. The information returned with the response depends on the method used in the request, for example:

  • GET - an entity corresponding to the requested resource is sent in the response;
  • PUT - a resource property was updated.

In the following example, the properties of a resource are requested.

Request:

GET /aps/2/resources/60a8e022-abac-4f79-9048-076716ab4b36
Accept: application/json

Response:

HTTP/1.1 200 OK
Content-type: application/json
Content-length: 1234

{
  ...

201 Created

The request has been fulfilled and resulted in creation of a new resource. The newly created resource can be referenced by the URI(s) returned in the entity of the response, with the most specific URI for the resource given by the Location header field. The response SHOULD include an entity containing a list of resource characteristics and location(s) from which the user or user’s agent can choose the one most appropriate. The entity format is specified by the media type given in the Content-Type header field. The origin server MUST create the resource before returning the 201 status code.

Example

Request

POST /aps/2/resources
Content-type: application/json
Content-length: 1234

{
   ...
}

Response:

HTTP/1.1 201 Created
Content-type: application/json
Content-length: 1234
Location: /aps/2/resources/60a8e022-abac-4f79-9048-076716ab4b36

{
  ...
}

204 No Content

The server has fulfilled the request but does not need to return an entity body. The 204 response MUST NOT include a message body, and thus it is always terminated by the first empty line after the header fields.

Request:

DELETE /aps/2/resources/60a8e022-abac-4f79-9048-076716ab4b36

Response:

HTTP/1.1 204 No Content

206 Partial Content

The server has fulfilled the partial GET request for the resource. The request MUST have included a Range header field RFC-2616 section 14.35) indicating the desired range, and MAY have included an If-Range header field RFC-2616 section 14.27) to make the request conditional.

The response MUST include a Content-Range header field RFC-2616 section 14.16) indicating the range included with this response, or a multipart/byteranges Content-Type including Content-Range fields for each part. If a Content-Length header field is present in the response, its value MUST match the actual number of OCTETs transmitted in the message body.

A cache MUST NOT combine a 206 response with other previously cached content.

A cache that does not support the Range and Content-Range headers MUST NOT cache 206 (Partial) responses.

Request:

GET /aps/2/resources?start=0&limit=10

Response:

HTTP/1.1 206 OK
Content-Type: application/json; charset=UTF-8
Content-Range: items 0-9/100
...

[
  ...
]

Error Responses

If an error occurs on the application side, the APS controller expects to receive a JSON object containing the error and message fields:

  • error - identifier of the error message
  • message - message text; it can be used as a translation key if needed

For example:

HTTP/1.1 500 Internal Server Error

{
   "message": "Internal Server Error: Resource repository is exhausted on the remote Application side",
   "error": "ApplicationUnknownError",
}

In the endpoint PHP code, to return an error message, you can throw an exception as in following example:

throw new \Exception("Resource repository is exhausted on the remote Application side");

The possible cases are compiled in the table.

APPLICATION RESPONSE APS CONTROLLER RESPONSE
{
“error”: “FailedToDoWhatIWanted”,
“message”: “This message should be shown to the user”
}
{
“error”: “FailedToDoWhatIWanted”,
“message”: “This message should be shown to the user”
}
<some>xml</some>
{
“error”: “ApplicationUnknownError”,
“message”: “<some>xml</some>”
}
{
“error”: “FailedToDoWhatIWanted”
}
{
“error”: “FailedToDoWhatIWanted”,
“message”: “Application returned error with an empty message”
}
{
“message”: “Show something to the user”
}
{
“error”: “ApplicationUnknownError”,
“message”: “Show something to the user”
}
-
{
“error”: “ApplicationUnknownError”,
“message”: “Application returned error with an empty message”
}