About global settings for the DINGO/API response

Source: Internet
Author: User

Question 1:
Dingo/api How to set the contents of the global return, such as the return field of success or not Status_code
DINGO/API, the default success is only the data field, no other fields;

Question 2:
Excuse me, dingo/api how to return XML or JSON based on the suffix name of the URL
Like what:
Http://api.server.dev/users.xml
Http://api.server.dev/users.json

========== 's Own solution ===========
About Question 2

Reply content:

Question 1:
Dingo/api How to set the contents of the global return, such as the return field of success or not Status_code
DINGO/API, the default success is only the data field, no other fields;

Question 2:
Excuse me, dingo/api how to return XML or JSON based on the suffix name of the URL
Like what:
Http://api.server.dev/users.xml
Http://api.server.dev/users.json

========== 's Own solution ===========
About Question 2

The first problem document says that you need to manually throw an exception class, http://laravelacademy.org/post/3842.html

or here: Https://github.com/dingo/api/wiki/Responses#responding-with-an-error

You should have asked the first question in the Laravel group, right? I didn't, but I didn't find you.

First of all, I didn't use DINGO/API, I'm sorry, but in my usual experience,

    • Problem one: At the same exit, all the returned data is in the same logic, so you can design your data structure in a global way.

    • Question two: At the same entrance, all requests go through the same portal to the interface data return structure (like your example, I can tell what kind of data return structure according to the URL suffix name), authentication, etc.

In essence, program design is to do the same entrance, the same exit

Problem one, no use, no understanding; question two, understanding the restful design pattern, TP's restful is to judge the return data type according to the URL suffix, XML, JSON, etc.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.