Creating a Content–Type Header
Depending on how you write your RESTlet, you might need to send a request body—and your RESTlet might return data you’ll want to use.
If your RESTlet needs a request body, add a Content-Type header for the right format.
If you leave out a required Content-Type header, your request will fail with a 415: Unsupported Media Type
error.
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.
Remember, Content-Type headers are case-sensitive—make sure you type them exactly as shown:
-
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, keep the following points in mind:
-
If your RESTlet uses a request body and its response matches that format, the returned data will follow that same format.
-
If you want the data format to be different from the request body, set the format using restlet.createResponse(options) when you return data.
-
If there’s no request body and your RESTlet returns data, the default is plain text.