我是一名PHP开发者,需要为移动应用程序开发者实现Web服务以共享数据,例如帖子、点赞等。
最佳的实现此类Web服务的方式是什么?是否有相关的标准?
目前,我使用JSON输出消息和内容等信息。
我的主要问题与应用程序开发人员有关的是错误消息。建议返回一个带有错误代码和消息的数组来显示:
$result = array(
'status' => false, // because registration failed
// if registration succeed then would be true
'errors' => array(
array(
'code' => '1',
'message' => 'Password is not strong enough!',
),
array(
'code' => '2',
'message' => 'Password and password confirmation do not match!',
),
array(
'code' => '3',
'message' => 'This email address has been used!',
),
),
);
但他们建议将所有错误信息作为字符串返回,只使用状态参数,如果状态为false,则会显示消息,类似于以下内容:
$result = array(
'status' => false,
'message' => 'Password is not strong enough!' . PHP_EOL .
'Password and password confirmation do not match!' . PHP_EOL .
'This email address has been used!',
);
提前感谢您。
这是需要翻译的内容。