API Maker

The framework for AI era

Database APIs

JSON, XML & YAML Output

The client picks the format and the shape of the response with a header.

Every API answers JSON by default. Send x-am-content-type-response: text/xml or text/yaml and the same response comes back as XML or YAML. Two more headers change the case of the keys and flatten nested objects, so each client gets data the way it reads it.

See it live

Step through it, slow it down, or open the full canvas.

api-maker/features/get-outputLive
  • Request
  • Stage
  • Response
  • Changed
Formats
3JSON · XML · YAML
Key cases
11to pick from
Headers
0in this request
Code
0to convert

JSON by default. Every API answers { success, statusCode, data } in JSON: generated, custom and system APIs alike.

How it works

  1. JSON by default.

    Every API answers { success, statusCode, data } in JSON: generated, custom and system APIs alike.

  2. XML with one header.

    Send x-am-content-type-response: text/xml and the same response comes as XML, each array item in an _el element.

  3. YAML the same way.

    text/yaml gives YAML, for tools and configuration systems that read it. No conversion code on either side.

  4. Flat objects for flat consumers.

    x-am-response-object-type: make_flat joins nested keys with an underscore: address.city becomes address_city.

  5. Keys in the case your app uses.

    x-am-response-case renames every key of the data: camelCase, PascalCase, snake_case, CONSTANT_CASE, param-case and more.

  6. Combine them freely.

    API Maker flattens first, then changes the case, then writes the format. Here: flat, camelCase keys, in YAML.

What you get

XML and YAML on request

text/xml (or application/xml) returns XML with a root element and each array item in an _el element. text/yaml returns YAML. JSON stays the default.

Keys in your case

camelCase, PascalCase, snake_case, CONSTANT_CASE, param-case, dot.case, path/case and more. Every key of the data is renamed, nested ones too.

Flat objects

make_flat joins nested keys with an underscore: address.city becomes address_city. Handy for grids, CSV and spreadsheets.

Every kind of API

Generated, schema, custom and system APIs all read the same headers. No conversion code in any of them.

Text, HTML and files from your code

A custom API sets g.res.contentType to answer plain text or an HTML page, or returns a file to download.

Applied in order

Flatten first, then the key case, then the format. The headers combine freely.

An example

One API, three clients

A web app reads JSON, a legacy ERP only imports XML, and an operations tool keeps its data in YAML. They all call the same API with their own header, and nobody writes a converter.

Ask for XMLrequest
GET /api/gen/admin/shop/main/products?limit=1&select=name,pricex-am-authorization: <API user token>x-am-content-type-response: text/xml
The same response in XMLresponse.xml
<?xml version='1.0'?><root>    <success>true</success>    <statusCode>200</statusCode>    <data>        <_el>            <_id>66f1c2…</_id>            <name>Mouse</name>            <price>19</price>        </_el>    </data></root>
Flat, camelCase, in YAMLrequest
GET /api/gen/admin/crm/main/customers?limit=1&select=name,addressx-am-authorization: <API user token>x-am-response-object-type: make_flatx-am-response-case: camelCasex-am-content-type-response: text/yaml

{ "address": { "zip_code": "395007" } } becomes addressZipCode: "395007" in the answer.

Good to know

  • Stream APIs always answer JSON.
  • The key case and flattening change the data of the response, not success, statusCode and the other fields around it.

Questions

Which values does x-am-content-type-response take?

application/json (default), text/xml or application/xml, text/yaml, and text/plain or text/html for responses whose data is a string.

Which cases does x-am-response-case support?

noChange (default), camelCase, capitalCase, constantCase, dotCase, headerCase, noCase, paramCase, pascalCase, pathCase, sentenceCase and snakeCase.

Are these responses cached separately?

Yes. With caching on, these headers are part of the cache key, so a JSON client never gets a cached XML answer.