코드에 RESTful 웹 서비스가 있고 이제는 여러 엔터티가있는 PUT-Method를 수행하는 동안 서버로 보낸 요청 날짜의 유효성을 검사해야합니다.제출 된 데이터의 유효성 검사가 RESTful 웹 서비스에서 실패한 경우 응답하는 방법은 무엇입니까?
그러나 지금 큰 질문은 다음과 같습니다. (아마도 많은) 유효성 검사 오류로 어떻게 응답합니까?
요청 방법 및 URL :
PUT http://example.dev/app_dev.php/api-1.0/labels.xml
요청 체 (서버가 수신 됨) :
array(size=2)
0 =>
array (size=11)
'id' => string '53' (length=2)
'name' => string '2222' (length=4)
'app_domain' => string '11' (length=2)
[...]
1 =>
array (size=12)
'id' => string '54' (length=2)
'name' => string 'testname2' (length=9)
'controllpanel_domain' => string 'testname2' (length=9)
'label' => string 'testname2' (length=9)
'app_domain' => string 'testname2' (length=9)
[...]
I은 다음 응답 끝낸다. JSON에서
<?xml version="1.0" encoding="UTF-8"?>
<result>
<status>
<![CDATA[error]]>
</status>
<code>400</code>
<text>
<![CDATA[Bad Request]]>
</text>
<message>
<![CDATA[Unable to validate label entities]]>
</message>
<violations>
<object>
<object>
<label>
<entry>
<violation_message>
<![CDATA[This value should not be blank]]>
</violation_message>
</entry>
</label>
<controllpanel_domain>
<entry>
<violation_message>
<![CDATA[This value should not be blank]]>
</violation_message>
</entry>
</controllpanel_domain>
<app_domain>
<entry>
<violation_message>
<![CDATA[This value is too short. It should have 3 characters or more]]>
</violation_message>
</entry>
<entry>
<violation_message>
<![CDATA[This value should be 333 or more]]>
</violation_message>
</entry>
</app_domain>
</object>
</object>
<object>
<object>
<controllpanel_domain>
<entry>
<violation_message>
<![CDATA[This value should be a valid number]]>
</violation_message>
</entry>
</controllpanel_domain>
<app_domain>
<entry>
<violation_message>
<![CDATA[This value should be a valid number]]>
</violation_message>
</entry>
</app_domain>
<login_left_text>
<entry>
<violation_message>
<![CDATA[This value should not be blank]]>
</violation_message>
</entry>
</login_left_text>
</object>
</object>
</violations>
</result>
: 더 나은 데이터
{
"status": "error",
"code": 400,
"text": "Bad Request",
"message": "Unable to validate label entities",
"violations": [
{
"object": {
"label": [
{
"violation_message": "This value should not be blank"
}
],
"controllpanel_domain": [
{
"violation_message": "This value should not be blank"
}
],
"app_domain": [
{
"violation_message": "This value is too short. It should have 3 characters or more"
},
{
"violation_message": "This value should be 333 or more"
}
]
}
},
{
"object": {
"controllpanel_domain": [
{
"violation_message": "This value should be a valid number"
}
],
"app_domain": [
{
"violation_message": "This value should be a valid number"
}
],
"login_left_text": [
{
"violation_message": "This value should not be blank"
}
]
}
}
]
}
응답 할 수 HTTP 상태 코드는 XML에서 400
입니까?