Using field aliases

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsUsing field aliases

Field aliases provide a simple way to replace raw SQL field names with user-friendly API names.

Try these examples in the 'API Docs' tab of the DreamFactory Admin Console or from the command line with cURL.

API Endpoint

GET https://{url}/api/v2/{api_name}/_table/{table_name}?fields={field_alias}

API Docs Screenshot

Swagger-field-alias.png

Example - Replace verbose SQL field name with field alias and use field alias in an API call.

Say we have a 'contact' table with long capitalized field names that are unusable in API calls. We need to get postal codes from the contact table, and would prefer to use 'postal_code' as a parameter in the API, instead of the raw SQL field name.

All we need to do is set up a field alias. To set up the field alias, navigate to the Schema tab and select the field you want to alias. In this example, we select the 'SOMEONE_ELSE_MADE_THIS_REALLY_LONG_FIELD_NAME_I_WISH_IT_WAS_SHORTER' field on the 'contact' table. Enter 'postal_code' as the field alias.

Field alias.png

Now we can make API calls to the 'contact' table and GET postal codes with the API-friendly 'postal_code' alias.

  • Table name: contact
  • Fields parameter in API call:
    postal_code
  • Request URL:
    https://foo.com/api/v2/mysql/_table/contact?fields=postal_code