Interface Specification Issues

Source: Internet
Author: User

Interface return data generally the shape and floating point type as a string output, you have to deal with this type?
What to do with the current laravel frame.

My idea is to define the data type on each model side, and then handle the model output uniformly, what's the best way to do it.

Reply content:

Interface return data generally the shape and floating point type as a string output, you have to deal with this type?
What to do with the current laravel frame.

My idea is to define the data type on each model side, and then handle the model output uniformly, what's the best way to do it.

PHP is a weakly typed language, so this situation is more common.
Generally, if you interact with JS, or other weakly typed languages, there is no problem.
If you have a strong language like Ios or Android, there are some problems

1, write a unified API processing function, in the output before the unified processing, is an int with intval to turn, is null is NULL, is an empty string, is "", this in the strong type needs attention.
2, interactive side, Ios, Android, etc., it is best to do type verification, you can do type conversion, do fault tolerance, do not return the wrong type of interface, the program will be collapsed.

It is best to deal with both sides.

This is not related to the framework, PHP is a weak type, so the data format is very irregular when returning JSON, I currently return the JSON data interface is on the outermost hand format

strval(xxx) //格式化为字符串intval(xxx) //格式化为整形数字floatval(xxx) //格式化为浮点型数字boolval(xxx) //格式化为浮点型

Thanks for the invitation, the upstairs is very clear, the PHP weak type, you can according to the data you want to accept, or return to your client's data alone with the program to do the processing, to ensure the integrity of the data accuracy. You can set a class or method to deal with the floating point, integer type and other data, in short, ensure that the interface security data correctness is good

First of all, say my results.
is not converted to a string.
is not your data is originally a string.

My PHP Version: 5.5.34
Laravel Framework version:5.2.22


  
   

顺便一提,我认为处理的时候应该是在controller返回的时候去统一处理。

  • Related Article

    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.