简单描述下问题场景
我想和后端接口请求用户名和ID用于展示在UI上面。两个字段即可(
userName
,id
),但是后端同学在接口中把用户性别/地址/电话/创建日期....全部返回过来。
我想了解下这样做有什么不妥,虽然对目前前端没有影响。
如果这样有问题我该如何和后端同学沟通
回复内容:
简单描述下问题场景
我想和后端接口请求用户名和ID用于展示在UI上面。两个字段即可(
userName
,id
),但是后端同学在接口中把用户性别/地址/电话/创建日期....全部返回过来。
我想了解下这样做有什么不妥,虽然对目前前端没有影响。
如果这样有问题我该如何和后端同学沟通
肯定是不好!
但是后端同学在做接口的时候,考虑的问题角度不同
<code>他可能觉得自己需要暴露更多的数据,以保证将来产品变化的时候(比如以前不需要的数据后来需要了)自己改动更小。 他可能使用同一个接口应付不同客户端的需求(app 和网站的需求的字段可能不同) 他可能偷懒, 直接把数据库model 序列化给你了。 </code>
我只说我自已团队的解决办法: 前端需要有自己的‘后端’ 。 前端同学使用 nodejs 封装出自己表现层需要的接口, 这样的接口不多也不少,需要什么返回什么。
我的理解中的 “前后端分离” 并不是运行在浏览器里面的js 就是前端, 运行在服务器里面的就是后端。
以前的普遍观点是后端用于处理数据,前端只用于展示。但是如今服务器的运算能力没有显著提升并且用户在增加,而用户手里的终端运算能力在不断提高。这样就可以把一些数据处理推给前端。这样用一些网络的流量来换取减轻服务器的负担,是完全合理的。
很有问题
如果可以通过这个接口看到别人的性别,地址,电话等等,是个很大的安全隐患
造成无谓的数据传输和带宽浪费(可以想象他从数据库读取肯定也是select * 的操作,所以这个浪费并不仅在前后端)
关于沟通的问题,你们需要一个接口定义的文档,双方明确约定应该返回什么,如果有额外的返回或者缺少,以文档说话,这比你直接指着他说出他的问题要合适的多
有不妥,字段过多造成网络延迟增加,用户体验变差,过多字段也容易泄露信息。
但是大部分应用还是更需要灵活性,所以其实多给点字段更好
资源浪费(如果是从缓存读的内容可以忽略)
安全,楼上说了,地址电话等可能会泄露
他懒
可以问他为什么不单独写个方法只查询你需要的数据
可以协商是否可以加入参数的方式在不新写方法的情况下满足你们各自的需求
不过还是建议跟楼上说的一样,约定好一个接口返回什么数据。
1、安全问题:用户的数据飞必要,都不要暴露出来,爆出来后,第三方用户可以爬取你们的用户信息。
2、网络传输:后端给前端返回的数据越多,占用的带宽或者网络流量就越多,对于使用手机流量的用户来说,很不友好。
3、开发规范:作为一个团队,肯定有自己的开发规范,对于不规范的地方及时沟通交流,内部强制执行规范。这样,久而久之,会有一套属于你们团队的好的规范。
最好的办法就是多写一些接口,满足不同的数据五万,千万不能做一个接口,满足万能数据要求,前后端都要泪奔~~~
如果你是领导可以开除他了
显然有问题。
主要问题在于他懒啊,因为他觉得你后面会再要别的字段(又要改),只是现在没想到就全弄出来了。
可以考虑规定一些字段是一定不会用到的。

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software