Content Types
- The user does not need to set the response content type to send JSON as a response.
- If the response content type is not set that means it is application/JSON.
If ContentType is set to below system will return data accordingly.
JSON = 'application/json'
XML = 'text/xml'
YAML = 'text/yaml'
TEXT = 'text/plain'
HTML = 'text/html'
Note: If content type is set and not from above list, then API Maker will consider it as base64 encoded.
title: HTML Response Example description: See a working example of returning HTML content using g.res.contentType = HTML in API Maker APIs.
HTML
Content type HTML | |
---|---|
Response
title: JSON Response Example description: View how g.res.contentType = JSON structures your APIs’ JSON response in API Maker with status codes, data, errors, and warnings.
JSON
Content type JSON | |
---|---|
Response
{
"success": false,
"statusCode": 555,
"data": "World",
"errors": [
{
"code": 401,
"message": "This is error"
}
],
"warnings": []
}
title: Octet Stream Response Example description: See how to stream binary data (like file downloads) using g.res.contentType = OCTET_STREAM in API Maker.
OCTET_STREAM
Content type OCTET_STREAM | |
---|---|
- It will download the image.
title: Plain Text Response Example description: Learn how to return a simple plain-text response with g.res.contentType = TEXT in API Maker.
TEXT
Content type TEXT | |
---|---|
Response
title: XML Response Example description: Demonstrates returning XML responses via g.res.contentType = XML in API Maker.
XML
Content type XML | |
---|---|
Response
<?xml version='1.0'?>
<root>
<success>true</success>
<statusCode>200</statusCode>
<data>Hello world from the API Maker.</data>
</root>
title: YAML Response Example description: Example of using g.res.contentType = YAML to respond in YAML format within API Maker.
YAML
Content type YAML | |
---|---|
Response