Welcome Guest, Not a member yet? Register   Sign In
Output based on the request type
#1

Hey guys,

i could need some advice.
I've an extensive application (200+ Models)

Lately we got more and more a situation where we need to output the content in different Types (XML, JSON, HTML, CSV, PDF and so on).
Our solution till now is like the following:

Extend the affected controller with a function json (e.g. for a json request) -> pick up the data from the model and send the data back
An Url looks like: /news/list/json or /news/list/xml and so on.
In this situation you can decide what you want.

The big downside is the redundancy - always put a function json in the controller method and so on.

My idea now is, to create a service like REST but with more options - which means i need to react based on the clients request.
This means, i need different base view folders like (views/xml/ etc.)
I don't think i have a problem to accomplish this from a technical point of view (extending the loader class and so on)

But does anybody know a fool proof method to determine such a request (maybe via content-type headers ?) or is my idea totally nuts ? Wink
Or are there any other solutions around ?

thx in advance for your answers
Reply
#2

Content-Type negotiation (via the Accept request header) is the standard and most fool-proof way to do this.
Reply
#3

If you're planing on doing a REST API, I can recommend this REST Server library that might help you with some stuff. https://github.com/chriskacerguis/codeig...restserver
Reply
#4

thx for your help guys
it looks like - this is something what i was looking for
Reply




Theme © iAndrew 2016 - Forum software by © MyBB