Get output in JSON/YAML/XML from any API response
- API Maker is capable of converting API responses in JSON or YAML or XML format automatically by just passing the return type in the header.
- Response of autogenerated API, custom API, or third-party API will be converted to YAML or XML automatically if the user passes
- “x-am-content-type-response” header value in the request.
JSON
{
"success": true,
"statusCode": 200,
"data": [
{
"_id": "5b794fb02fe51f2ead6919da",
"active": 1,
"updatedAt": "2018-08-19T11:08:32.5822",
"createdAt": "2018-08-19T11:08:32.5822",
"company_name": "prayosha",
"company_type": "PRODUCTION",
"__v": 0
}
]
}
XML
<?xml version='1.0'?>
<root>
<success>true</success>
<statusCode>200</statusCode>
<data>
<_el>
<_id>5b794fb02fe51f2ead6919da</_id>
<active>1</active>
<updatedAt>2018-08-19T11:08:32.5822</updatedAt>
<createdAt>2018-08-19T11:08:32.5822</createdAt>
<company_name>prayosha</company_name>
<company_type>PRODUCTION</company_type>
<__v>0</__v>
</_el>
</data>
</root>
YAML
success: true
statusCode: 200
data:
_id: 5b794fb02fe51f2ead6919da
active: 1
updatedAt: 2018-08-19T11:08:32.5822
createdAt: 2018-08-19T11:08:32.5822
company_name: prayosha
company_type: PRODUCTION
__v: 0
User-defined Response pattern [flat/hierarchical]
- If we want to make the output structure flat, it is also done automatically. it makes API easily consumable in case of nested structure response. Just need to pass header “x-am-response-object-type” with the value “flat”.
- It can work in conjuction with “x-am-response-case” and “x-am-content-type-response” also.
- As you can see below example, how easily it can convert N number of nested levels of response in just simple flat response,
- By using this feature, we can easily save response to any SQL database which does not support nested-level of fields like MongoDB.
Default Nested Response
{
"success": true,
"statusCode": 200,
"data": {
"hello": "world",
"level1": {
"level3": {
"level3": {
"name": "API Maker"
}
}
}
}
}
Flat Response
{
"success": true,
"statusCode": 200,
"data": {
"hello": "world",
"level1_level2_level3_name": "API Maker"
}
}
Response case changes automatically
We can change response data to any case. Just need to pass the relevant value in the request header “x-am-response-case
- The example above is the default response of any API
- We passed the “x-am-response-case” value as “pascalCase” and it will return the API response as shown below.
Below types of response cases are supported
- camelCase
- capitalCase
- constantCase
- dotCase
- headerCase
- noCase
- paramCase
- pascalCase
- pathCase
- sentenceCase
- snakeCase
Default JSON Response
{
"success": true,
"statusCode": 200,
"data": [
{
"_id": "5b794fb02fe51f2ead6919da",
"active": 1,
"updatedAt": "2018-08-19T11:08:32.5822",
"createdAt": "2018-08-19T11:08:32.5822",
"company_name": "prayosha",
"company_type": "PRODUCTION",
"__v": 0
}
]
}
ConstantCase JSON Response
{
"success": true,
"statusCode": 200,
"data": [
{
"_ID": "5b794fb02fe51f2ead6919da",
"ACTIVE": 1,
"UPDATEDAT": "2018-08-19T11:08:32.5822",
"CREATEDAT": "2018-08-19T11:08:32.5822",
"COMPANY_NAME": "prayosha",
"COMPANY_TYPE": "PRODUCTION",
"__V": 0
}
]
}
Default XML Response
<?xml version='1.0'?>
<root>
<success>true</success>
<statusCode>200</statusCode>
<data>
<_el>
<_id>5b794fb02fe51f2ead6919da</_id>
<active>1</active>
<updatedAt>2018-08-19T11:08:32.5822</updatedAt>
<createdAt>2018-08-19T11:08:32.5822</createdAt>
<company_name>prayosha</company_name>
<company_type>PRODUCTION</company_type>
<__v>0</__v>
</_el>
</data>
</root>
ConstantCase XML Response
<?xml version='1.0'?>
<root>
<success>true</success>
<statusCode>200</statusCode>
<data>
<_el>
<_ID>5b794fb02fe51f2ead6919da</_ID>
<ACTIVE>1</ACTIVE>
<UPDATEDAT>2018-08-19T11:08:32.5822</UPDATEDAT>
<CREATEDAT>2018-08-19T11:08:32.5822</CREATEDAT>
<COMPANY_NAME>prayosha</COMPANY_NAME>
<COMPANY_TYPE>PRODUCTION</COMPANY_TYPE>
<__V>0</__V>
</_el>
</data>
</root>
Default YAML Response
success: true
statusCode: 200
data:
_id: 5b794fb02fe51f2ead6919da
active: 1
updatedAt: 2018-08-19T11:08:32.5822
createdAt: 2018-08-19T11:08:32.5822
company_name: prayosha
company_type: PRODUCTION
__v: 0
ConstantCase YAML Response
success: true
statusCode: 200
data:
_ID: 5b794fb02fe51f2ead6919da
ACTIVE: 1
UPDATEDAT: 2018-08-19T11:08:32.5822
CREATEDAT: 2018-08-19T11:08:32.5822
COMPANY_NAME: prayosha
COMPANY_TYPE: PRODUCTION
__V: 0