Author Topic: return format  (Read 1484 times)

waveiswater

  • Newbie
  • *
  • Posts: 13
    • View Profile
return format
« on: December 28, 2008, 07:52:19 am »
I am using TinyMVC as a framework for building services, or simple APIs.  I would like to be able to add a return format to the end of the url.  For example

http://www.example.com/controller/action.xml

would return xml

http://www.example.com/controller/action.json

would return json

any ideas how this could be done?

Thanks

Todd

mohrt

  • Administrator
  • Sr. Member
  • *****
  • Posts: 275
    • View Profile
Re: return format
« Reply #1 on: December 28, 2008, 09:33:26 am »
The content type is set by your PHP application:

Code: [Select]
header("Content-type: text/xml");
// spit out xml here

As for the URL, you could do something like:

http://www.example.com/controller/action/page.xml

Then grab the third uri segment and use the suffix to determine the content type.