Documentation for LLMs on building APIs with the Apia framework
Field specs control which fields are included in a response. They allow endpoints to specify a subset of fields to return from nested objects, and allow clients to request specific fields.
By default, all fields on an object are included in the response. You can control the default included fields using the include option on a field.
class InfoEndpoint < BaseEndpoint
# Include all top-level fields, plus specific nested fields
field :organization, Objects::Organization, include: "*,users[user_id,owner,roles,organization_id]"
end
class Time < Apia::Object
field :time, type: Objects::Time, include: "unix,day_of_week"
end
| Syntax | Meaning |
|---|---|
* |
All top-level fields |
field_name |
Include a specific field |
field1,field2 |
Include multiple fields |
field[subfield1,subfield2] |
Include specific subfields of a nested object |
field[+extra_field] |
Include a field in addition to the defaults |
field[-excluded_field] |
Exclude a field from the defaults |
field :user, Objects::User, include: "*"
field :user, Objects::User, include: "id,name,email"
field :organization, Objects::Organization, include: "*,users[user_id,owner]"
This includes all top-level Organization fields and for the nested users field, only includes user_id and owner.
include: on a field, it sets the default field specField conditions (defined with condition blocks on objects/fields) are evaluated separately from field specs. Both must pass for a field to be included.