adr-example icon indicating copy to clipboard operation
adr-example copied to clipboard

Responding in Various Formats

Open mikesoule opened this issue 4 years ago • 0 comments

@pmjones Quick question but I thought I'd ask it here for everyone's benefit.

When responding with the same payload but in more than 1 format (for instance, user may request JSON, CSV, or XML), how would you structure your responder classes?

Some options I'm considering (and caveats):

  1. Have abstract JSON, CSV, and XML responders. (Possible inheritance hell)
  2. Make each responder handle all possible formats. (Huge responders, likely code repetition)
  3. Use traits for serializing payloads to each format. (Only allows for generic serialization, no custom logic per responder)
  4. Become a graphic designer. (More free time but even fewer problems with concrete answers)

mikesoule avatar Dec 02 '19 22:12 mikesoule