Frank Michael Sanchez
Frank Michael Sanchez

Reputation: 245

SLIM PHP Routing Type

I'm working on updating my Slim API and wanted to add the ability to define the type of response for a route within the routes url. Similar to how Reddit or Rails does it where you can add a .html,.json, or .xml to a route and have that route return the proper formatted data. Below is a Reddit example of one route being able to return a json,xml, or html response by changing the ending to whatever response type.

http://www.reddit.com/r/ObjectiveC.json

Is this something I will have to do manually with middleware parsing every route or does Slim have this built in? Any help would be greatly appreciated.

Thanks

Upvotes: 3

Views: 362

Answers (1)

Jeremy Kendall
Jeremy Kendall

Reputation: 2869

What you're looking for isn't natively available, but you might want to look at the ContentTypes Middleware in the Slim-Middleware repo. I think that'll get you close to where you need to go, although the type is detected via the content type header via \Slim\Http\Request::getMediaType.

Upvotes: 1

Related Questions