Creating a Content–Type Header
Depending on how the RESTlet is written, requests to that RESTlet may require a request body in its HTTP request. The RESTlet may also return an HTTP response with data that you may want to use.
If your RESTlet requires a request body, you need to add a Content-Type header to the request body with its corresponding format.
When a Content-Header is required but is missing, the request fails with an HTTP error code reading 415: Unsupported Media Type
.
The following are suggested Content-Type headers:
-
application/json – used for RESTlets that require request bodies that map values to fields.
-
application/xml – used for RESTlets that are invoked through the GET method.
-
text/plain – used for RESTlets that require limited or simple input.
Note that Content-Type headers are case-sensitive and must be specified as follows:
-
Content-Type: application/json
-
Content-Type: application/xml
-
Content-Type: text/plain
For an example of a shell script that generates a Content-Type header, see Example of a Shell Script that Calls a RESTlet.
If your RESTlet returns data, take note of the following:
-
If your RESTlet has a request body and the RESTlet data has the same format as the request body, the RESTlet data follows the format specified in the request body.
-
If you want your RESTlet data to have a different format than the request body of your RESTlet, you must specify the format for your RESTlet data using restlet.createResponse(options) when returning the RESTlet data.
-
If your RESTlet does not have a request body and your RESTlet is returning data, the default format is plain text.