向一个数据表添加一条记录。
请求示例:
curl -X POST \
-H "X-Bmob-Application-Id: Your Application ID" \
-H "X-Bmob-REST-API-Key: Your REST API Key" \
-H "Content-Type: application/json" \
-d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' \
https://api.bmob.cn/1/classes/GameScore响应示例:
{
"createdAt": "2011-08-20 02:06:57",
"objectId": "e1kXT22L"
}一次创建多条数据记录。
请求示例:
curl -X POST \
-H "X-Bmob-Application-Id: Your Application ID" \
-H "X-Bmob-REST-API-Key: Your REST API Key" \
-H "Content-Type: application/json" \
-d '{
"requests": [
{
"method": "POST",
"path": "/1/classes/GameScore",
"body": {
"score": 1337,
"playerName": "Sean Plott"
}
},
{
"method": "POST",
"path": "/1/classes/GameScore",
"body": {
"score": 1338,
"playerName": "ZeroCool"
}
}
]
}' \
https://api.bmob.cn/1/batch更新一条已存在的数据记录。
请求示例:
curl -X PUT \
-H "X-Bmob-Application-Id: Your Application ID" \
-H "X-Bmob-REST-API-Key: Your REST API Key" \
-H "Content-Type: application/json" \
-d '{"score":73453}' \
https://api.bmob.cn/1/classes/GameScore/e1kXT22L原子计数器可以让计数字段自增或自减。
请求示例:
curl -X PUT \
-H "X-Bmob-Application-Id: Your Application ID" \
-H "X-Bmob-REST-API-Key: Your REST API Key" \
-H "Content-Type: application/json" \
-d '{"score":{"__op":"Increment","amount":1}}' \
https://api.bmob.cn/1/classes/GameScore/e1kXT22L向数组字段添加或删除元素。
请求示例:
curl -X PUT \
-H "X-Bmob-Application-Id: Your Application ID" \
-H "X-Bmob-REST-API-Key: Your REST API Key" \
-H "Content-Type: application/json" \
-d '{
"skills": {
"__op": "Add",
"objects": ["flying", "kungfu"]
}
}' \
https://api.bmob.cn/1/classes/GameScore/e1kXT22L请求示例:
curl -X PUT \
-H "X-Bmob-Application-Id: Your Application ID" \
-H "X-Bmob-REST-API-Key: Your REST API Key" \
-H "Content-Type: application/json" \
-d '{
"skills": {
"__op": "Remove",
"objects": ["flying"]
}
}' \
https://api.bmob.cn/1/classes/GameScore/e1kXT22L删除一条数据记录。
请求示例:
curl -X DELETE \
-H "X-Bmob-Application-Id: Your Application ID" \
-H "X-Bmob-REST-API-Key: Your REST API Key" \
https://api.bmob.cn/1/classes/GameScore/e1kXT22L删除对象中的某个字段。
请求示例:
curl -X PUT \
-H "X-Bmob-Application-Id: Your Application ID" \
-H "X-Bmob-REST-API-Key: Your REST API Key" \
-H "Content-Type: application/json" \
-d '{"fieldName":{"__op":"Delete"}}' \
https://api.bmob.cn/1/classes/GameScore/e1kXT22L创建对象时可以关联其他对象。
请求示例:
curl -X POST \
-H "X-Bmob-Application-Id: Your Application ID" \
-H "X-Bmob-REST-API-Key: Your REST API Key" \
-H "Content-Type: application/json" \
-d '{
"playerName": "Sean Plott",
"game": {
"__type": "Pointer",
"className": "Game",
"objectId": "game123"
}
}' \
https://api.bmob.cn/1/classes/GameScore查询时可以返回关联对象的详细信息。
请求示例:
curl -X GET \
-H "X-Bmob-Application-Id: Your Application ID" \
-H "X-Bmob-REST-API-Key: Your REST API Key" \
https://api.bmob.cn/1/classes/GameScore?include=game一个对象可以关联多个其他对象。
请求示例:
curl -X POST \
-H "X-Bmob-Application-Id: Your Application ID" \
-H "X-Bmob-REST-API-Key: Your REST API Key" \
-H "Content-Type: application/json" \
-d '{
"playerName": "Sean Plott",
"games": {
"__type": "Relation",
"objects": [
{
"__type": "Pointer",
"className": "Game",
"objectId": "game123"
},
{
"__type": "Pointer",
"className": "Game",
"objectId": "game456"
}
]
}
}' \
https://api.bmob.cn/1/classes/GameScore对数字字段进行原子增减操作。
请求示例:
curl -X PUT \
-H "X-Bmob-Application-Id: Your Application ID" \
-H "X-Bmob-REST-API-Key: Your REST API Key" \
-H "Content-Type: application/json" \
-d '{
"score": {
"__op": "Increment",
"amount": 1
}
}' \
https://api.bmob.cn/1/classes/GameScore/e1kXT22L对数组字段进行原子添加或删除操作。
请求示例:
curl -X PUT \
-H "X-Bmob-Application-Id: Your Application ID" \
-H "X-Bmob-REST-API-Key: Your REST API Key" \
-H "Content-Type: application/json" \
-d '{
"skills": {
"__op": "AddUnique",
"objects": ["flying"]
}
}' \
https://api.bmob.cn/1/classes/GameScore/e1kXT22L一次更新多条数据。
请求示例:
curl -X POST \
-H "X-Bmob-Application-Id: Your Application ID" \
-H "X-Bmob-REST-API-Key: Your REST API Key" \
-H "Content-Type: application/json" \
-d '{
"requests": [
{
"method": "PUT",
"path": "/1/classes/GameScore/e1kXT22L",
"body": {
"score": 999
}
},
{
"method": "PUT",
"path": "/1/classes/GameScore/a2kXT34M",
"body": {
"score": 888
}
}
]
}' \
https://api.bmob.cn/1/batch一次删除多条数据。
请求示例:
curl -X POST \
-H "X-Bmob-Application-Id: Your Application ID" \
-H "X-Bmob-REST-API-Key: Your REST API Key" \
-H "Content-Type: application/json" \
-d '{
"requests": [
{
"method": "DELETE",
"path": "/1/classes/GameScore/e1kXT22L"
},
{
"method": "DELETE",
"path": "/1/classes/GameScore/a2kXT34M"
}
]
}' \
https://api.bmob.cn/1/batch- 批量操作每次最多支持50条记录
- 数据更新操作会自动更新 updatedAt 字段
- 删除操作是不可逆的,请谨慎操作
- 关联对象的操作要注意维护数据一致性
- 原子操作可以避免并发问题
- 建议使用批量操作来提高性能
- 数据操作需要合适的 ACL 权限
常见错误码:
| 错误码 | 描述 |
|---|---|
| 101 | 对象不存在 |
| 111 | 字段类型不匹配 |
| 136 | 操作超过限制 |
| 137 | 重复的值 |
| 139 | 角色名无效 |