简体   繁体   English

Luracast Restler JSON格式验证

[英]Luracast Restler JSON format validation

I am wondering if Restler handle validation on JSON request format? 我想知道Restler是否可以处理JSON请求格式的验证?

In example, I have this JSON request: 例如,我有这个JSON请求:

{ "id" : 1, "party_id" : , "description" : "say it here" }

The value for party_id should invalid. party_id的值应无效。 Any insights? 有什么见解吗? Thanks. 谢谢。

JSON Validation in Restler 2.0.5 Restler 2.0.5中的JSON验证

Starting from Restler version 2.0.5, restler automatically throws HTTP 400 status with a meaningful error message when the JSON body in the request is malformed. Restler 2.0.5版开始,当请求中的JSON主体格式错误时,restler会自动引发HTTP 400状态并显示有意义的错误消息。

for example 例如

curl -X POST http://restler2.dev/examples/_006_crud/index.php/author -H "Content-Type: application/json" -d '{"name": "Another", "email": "another@email.com'

returns 退货

{
  "error": {
    "code": 400,
    "message": "Bad Request: Error parsing JSON, malformed JSON"
  }
}

It requires PHP 5.3 and above 需要PHP 5.3以上

Update 更新

Restler 2.0.6 adds error support for older versions of PHP 5 Restler 2.0.6添加了对旧版本PHP 5的错误支持

So help.luracast.com/restler/examples which is using PHP 5.2.17 will return the following response for cURL 因此,使用PHP 5.2.17的help.luracast.com/restler/examples将为cURL返回以下响应

curl -X POST http://help.luracast.com/restler/examples/_006_crud/index.php/authr -H "Content-Type: application/json" -d '{"name": "Another", "email": "another@email.com",}'

{
  "error": {
    "code": 400,
    "message": "Bad Request: Error parsing JSON"
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM