首页 > laravel如何更具后缀名.json,.xml返回对应的格式?

laravel如何更具后缀名.json,.xml返回对应的格式?

laravel如何更具后缀名.json,.xml返回对应的格式?

准确的说如何优雅的实现?
我用这个方式感觉太丑了(这个是dingoAPI的route)


没用过dingo,但在restful风格中,返回格式应该是通过Accept头来磋商的

GET /users/1
Accept: application/json

==>

200 OK
Content-Type: application/json

{"name":"foo"}
GET /users/1
Accept: application/xml

==>

200 OK
Content-Type: application/xml

<response><name>foo</name></response>
【热门文章】
【热门文章】