Configuration
API-level configuration applies to all resources within the API.
Key Format
key_format controls how keys are transformed in requests and responses:
Apiwork::API.define '/api/v1' do
key_format :camel
endOptions:
| Option | Ruby Key | JSON Key |
|---|---|---|
:keep (default) | created_at | created_at |
:camel | created_at | createdAt |
:pascal | created_at | CreatedAt |
:kebab | created_at | created-at |
:underscore | created_at | created_at |
Path Format
path_format controls how URL path segments are formatted:
Apiwork::API.define '/api/v1' do
path_format :kebab
resources :recurring_invoices
# Routes: GET /api/v1/recurring-invoices
endOptions:
| Option | Example Input | URL Path |
|---|---|---|
:keep (default) | :recurring_invoices | recurring_invoices |
:camel | :recurring_invoices | recurringInvoices |
:pascal | :recurring_invoices | RecurringInvoices |
:kebab | :recurring_invoices | recurring-invoices |
:underscore | :recurring_invoices | recurring_invoices |
Custom Member and Collection Actions
Custom actions are also transformed:
Apiwork::API.define '/api/v1' do
path_format :kebab
resources :invoices do
member do
patch :mark_as_paid # PATCH /invoices/:id/mark-as-paid
end
collection do
get :past_due # GET /invoices/past-due
end
end
endINFO
path_format transforms all URL path segments:
- The base path (
/cool_manbecomes/cool-manwith:kebab) - Resource names (
recurring_invoicesbecomesrecurring-invoices) - Custom action names (
mark_as_paidbecomesmark-as-paid) - Explicit
path:options
It does not affect:
- Route parameters (
:id,:post_id) - Query parameters
- Request/response payload keys (use key_format for those)
Explicit Path Override
The resource name can be overridden with explicit path::
resources :recurring, path: 'recurring_invoices'
# With path_format :kebab: GET /api/v1/recurring-invoices
# Controller: RecurringController (unchanged)The explicit path is still transformed according to path_format.
With Key Format
path_format and key_format are independent:
Apiwork::API.define '/api/v1' do
key_format :camel # Payload keys: createdAt
path_format :kebab # URL paths: recurring-invoices
endAdapter Configuration
The adapter block configures the Standard Adapter (default). If using a custom adapter, configuration may differ.
Apiwork::API.define '/api/v1' do
adapter do
pagination do
default_size 20
max_size 100
end
end
endSee Standard Adapter for all configuration options.
Using a Custom Adapter
A registered adapter is selected by name:
Apiwork::API.define '/api/v1' do
adapter :jsonapi
endOr switch and configure:
Apiwork::API.define '/api/v1' do
adapter :jsonapi do
pagination do
strategy :cursor
end
end
endSee Custom Adapters for creating a custom adapter.
See also
- API::Base reference — all configuration methods and options