adr-example
adr-example copied to clipboard
Responding in Various Formats
@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):
- Have abstract JSON, CSV, and XML responders. (Possible inheritance hell)
- Make each responder handle all possible formats. (Huge responders, likely code repetition)
- Use traits for serializing payloads to each format. (Only allows for generic serialization, no custom logic per responder)
- Become a graphic designer. (More free time but even fewer problems with concrete answers)