Hi all,

Apologies if I have missed some obvious documentation somewhere. Feel free to respond with just a link to some docs.

What is the current best-practice for altering the output of JSONAPI for a particular entity type? My impression is that in the past it was a "Normalizer" approach, but that this is no longer supported with the latest JSONAPI code. Any and all ideas are welcome. Thank you very much!

Comments

brockfanning created an issue. See original summary.

brockfanning’s picture

Maybe answering my own question, I found the following in this blog post:

Supported patterns are:

  1. Create a computed field. Note that a true computed field will be calculated on every entity load, which may be a good or a bad thing depending on the use case. You can also create stored fields that are calculated on entity presave. The linked documentation has examples for both methods.
  2. Write a normalizer at the Data Type level, instead of field or entity level. As a benefit, this normalizer will also work in core REST!
  3. Create a Field Enhancer plugin like these, using JSON:API Extras. This is the most similar pattern, it enforces you to define the schema of the enhancer.

I'll investigate the Field Enhancer approach, report my results here and close this issue.

brockfanning’s picture

Status: Active » Fixed

I don't know if it's the best "best practice", but the field enhancer approach is getting the job done.

e0ipso’s picture

Thanks for the contribution @brockfanning. Yes, Field Enhancers in JSON:API Extras are the recommended way. Take a look at https://humanbits.es/web-development/2019/01/07/jsonapi-2/#no-more-custo... for a bit more context.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.