Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SLIM PHP Routing Type

Tags:

rest

php

slim

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

like image 714
Frank Michael Sanchez Avatar asked Mar 25 '26 06:03

Frank Michael Sanchez


1 Answers

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.

like image 147
Jeremy Kendall Avatar answered Mar 27 '26 20:03

Jeremy Kendall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!