Reviewer · API
Match client resources to API
Client-side resources, route params, and request/response handling should mirror the actual API contract as closely as possible—same field names, types, and HTTP verbs as documented—rather than introducing divergent client-only representations. When the API docs specify a field as a string (e.g. `listing_visibility`), keep the resource/model typed as a...
Client-side resources, route params, and request/response handling should mirror the actual API contract as closely as possible—same field names, types, and HTTP verbs as documented—rather than introducing divergent client-only representations. When the API docs specify a field as a string (e.g. listing_visibility), keep the resource/model typed as a string and only convert to UI-friendly types (e.g. booleans for toggle components) at the edges—inside form classes or display components—never deep in shared models where the transformation is easy to lose track of. Similarly, dynamic route segments should use the same name as the API parameter they represent (e.g. snapshot_id) so navigation code and API calls stay consistent, and before changing an HTTP verb (PUT vs POST) confirm against the API docs which methods are actually supported rather than relying on incidental behavior from a data layer. This keeps client code predictable and reduces the amount of implicit, hard-to-trace data mutation as the codebase moves away from frameworks (like Ember Data) that previously centralized such transformations.
Example:
// Resource should match API shape (string, not boolean)
new AuthMethodResource({ path, type, config: { listing_visibility: 'hidden' } });
// Convert only at the UI boundary, e.g. in the form component
toJSON() {
return { listing_visibility: this.listingVisibilityBoolean ? 'hidden' : 'unauth' };
}