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

ringa_lee
Release: 2023-02-28 11:18:02
Original
1319 people have browsed it

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

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

回复内容:

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>
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template