active_model_serializers icon indicating copy to clipboard operation
active_model_serializers copied to clipboard

Introduces per-request adapter switching based on the request mime.

Open rescribet opened this issue 8 years ago • 1 comments

Purpose

The current behaviour is to always use the same adapter, this is not very desirable in more formal hypermedia conforming systems where content-negotiation determines the format which should be used. This PR introduces the option to let the system choose the adapter based on the negotiation results.

Changes

Content-type determination is left to ActionController::MimeResponds, so that users won't have to specify the adapter in every render call.

Caveats

  • This implementation uses a non-existent virtual adapter :mime to let the subsystem know to look up the adapter dynamically, which may be considered inconsistent.
  • By using MimeResponds, an implicit dependency between mime types and serializers is created, which might not be suitable for projects needing to use different adapters under the same mime type.
  • I'm not aware how these changes will affect view caching.

Related GitHub issues

@remear's comment on PR https://github.com/rails-api/active_model_serializers/pull/1082 was the cause to reimplement this feature. https://github.com/rails-api/active_model_serializers/issues/1039

rescribet avatar May 02 '17 15:05 rescribet

@fletcher91, thanks for your PR! By analyzing the history of the files in this pull request, we identified @bf4, @domitian and @bacarini to be potential reviewers.

mention-bot avatar May 02 '17 15:05 mention-bot