内容操作(新)

本文档介绍了内容的获取(包括内容表的自定义字段)和内容的创建、编辑和删除等操作

获取内容详情

接口

GET https://cloud.minapp.com/oserve/v1/content/:content_group_id/text/:text_id/

其中 content_group_id 是内容库的 ID, text_id 是内容的 ID

代码示例

  1. curl -X GET \
  2. -H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
  3. -H "Content-Type: application/json" \
  4. https://cloud.minapp.com/oserve/v1/content/1/text/1/
  1. var request = require("request");
  2. var options = { method: 'GET',
  3. url: 'https://cloud.minapp.com/oserve/v1/content/1/text/1/',
  4. headers:
  5. { 'Content-Type': 'application/json',
  6. Authorization: 'Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4' } };
  7. request(options, function (error, response, body) {
  8. if (error) throw new Error(error);
  9. console.log(body);
  10. });
  1. <?php
  2. $content_group_id = 1; // 内容库 ID
  3. $text_id = 1; // 内容 ID
  4. $url = "https://cloud.minapp.com/oserve/v1/content/{$content_group_id}/text/{$text_id}/";
  5. $ch = curl_init();
  6. $header = array(
  7. "Authorization: Bearer {$token}",
  8. 'Content-Type: application/json; charset=utf-8'
  9. );
  10. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  11. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  12. curl_setopt($ch, CURLOPT_URL, $url);
  13. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  14. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  15. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  16. $res = curl_exec($ch);
  17. curl_close($ch);

返回示例

  1. {
  2. "id": 1,
  3. "title": "Title",
  4. "content": "",
  5. "cover": null,
  6. "description": "",
  7. "group_id": 1,
  8. "categories": [
  9. {
  10. "id": 1,
  11. "name": "category",
  12. "parent": null
  13. }
  14. ],
  15. "created_at": 1516950540,
  16. "updated_at": 1517800400
  17. }

返回参数说明

参数类型说明
idInteger内容 ID
titleString内容标题
contentString详细容
coverString封面图
descriptionString内容摘要
group_idInteger内容库 ID
categoriesObject Array内容所属分类
created_atInteger内容创建时间
updated_atInteger内容更新时间

获取内容列表

接口

GET https://cloud.minapp.com/oserve/v1/content/:content_group_id/text/

提交参数

内容查询与数据表接口查询保持一致

代码示例

  1. curl -X GET \
  2. -H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
  3. -H "Content-Type: application/json" \
  4. https://cloud.minapp.com/oserve/v1/content/1/text/
  1. var request = require("request");
  2. var options = { method: 'GET',
  3. url: 'https://cloud.minapp.com/oserve/v1/content/1/text/',
  4. headers:
  5. { 'Content-Type': 'application/json',
  6. Authorization: 'Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4' } };
  7. request(options, function (error, response, body) {
  8. if (error) throw new Error(error);
  9. console.log(body);
  10. });
  1. <?php
  2. $content_group_id = 1; // 内容库 ID
  3. $url = "https://cloud.minapp.com/oserve/v1/content/{$content_group_id}/text/";
  4. $ch = curl_init();
  5. $header = array(
  6. "Authorization: Bearer {$token}",
  7. 'Content-Type: application/json; charset=utf-8',
  8. );
  9. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  10. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  11. curl_setopt($ch, CURLOPT_URL, $url);
  12. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  13. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  14. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  15. $res = curl_exec($ch);
  16. curl_close($ch);

返回示例

  1. {
  2. "meta": {
  3. "limit": 20,
  4. "next": null,
  5. "offset": 0,
  6. "previous": null,
  7. "total_count": 1
  8. },
  9. "objects": [
  10. {
  11. "id": 1,
  12. "title": "Title",
  13. "content": "",
  14. "cover": null,
  15. "description": "",
  16. "group_id": 1,
  17. "categories": [
  18. {
  19. "id": 1,
  20. "name": "category",
  21. "parent": null
  22. }
  23. ],
  24. "created_at": 1516950540,
  25. "updated_at": 1517800400
  26. }
  27. ]
  28. }

创建内容

接口

POST https://cloud.minapp.com/oserve/v1/content/:content_group_id/text/

参数说明

Content-Type: application/json

内容表内置字段:

参数类型说明
idInteger内容 ID
titleString内容标题
contentString详细容
coverFile封面图
descriptionString内容摘要
group_idInteger内容库 ID
categoriesInteger Array内容所属分类
created_atInteger内容创建时间
updated_atInteger内容更新时间

内容接口参数格式将与数据表接口保持一致

字段 group_id 将会被接口自动赋值,所以即使提交的数据中有 group_id 也将会被覆盖

代码示例

  1. curl -X POST \
  2. -H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
  3. -H "Content-Type: application/json" \
  4. -d '{"title": "Test Title"}' \
  5. https://cloud.minapp.com/oserve/v1/content/1/text/
  1. var request = require("request");
  2. var options = { method: 'POST',
  3. url: 'https://cloud.minapp.com/oserve/v1/content/1/text/',
  4. headers:
  5. { 'Content-Type': 'application/json',
  6. Authorization: 'Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4' },
  7. body: { title: 'Test Title' },
  8. json: true };
  9. request(options, function (error, response, body) {
  10. if (error) throw new Error(error);
  11. console.log(body);
  12. });
  1. <?php
  2. $content_group_id = 1;
  3. $param['title'] = 'TestCreateGroup';
  4. $url = "https://cloud.minapp.com/oserve/v1/content/{$content_group_id}/text/";
  5. $ch = curl_init();
  6. $header = array(
  7. "Authorization: Bearer {$token}",
  8. 'Content-Type: application/json; charset=utf-8'
  9. );
  10. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  11. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  12. curl_setopt($ch, CURLOPT_URL, $url);
  13. curl_setopt($ch, CURLOPT_POST, true);
  14. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($param));
  15. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  16. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  17. $res['response'] = curl_exec($ch); // 反馈结果
  18. $res['status_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 请求状态码
  19. curl_close($ch);

返回示例

  1. {
  2. "id": 2,
  3. "title": "Test Title",
  4. "group_id": 1,
  5. "categories": [],
  6. "created_at": 1519960085,
  7. "updated_at": 1519960085
  8. }

在发送创建内容的请求没有对一些内置字段如 content、description 或自定义字段赋值时,接口返回的字段将不会包含这些未被赋值的字段;若希望接口返回所有的字段,可以在创建内容的请求中携带所有的字段;接口会根据字段在数据表中定义的类型对提交的数据进行强类型的判断,提交的数据类型不合法,接口将会过滤掉这些字段,只存储合法的字段

状态码说明

201: 创建成功

400: 提交数据为空;提交的数据都不合法

编辑内容

接口

PUT https://cloud.minapp.com/oserve/v1/content/:content_group_id/text/:text_id/

代码示例

  1. curl -X PUT \
  2. -H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
  3. -H "Content-Type: application/json" \
  4. -d '{"title": "Test Category"}' \
  5. https://cloud.minapp.com/oserve/v1/content/1/text/2/
  1. var request = require("request");
  2. var options = { method: 'PUT',
  3. url: 'https://cloud.minapp.com/oserve/v1/content/1/text/2/',
  4. headers:
  5. { 'Content-Type': 'application/json',
  6. Authorization: 'Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4' },
  7. body: { title: 'Test Category' },
  8. json: true };
  9. request(options, function (error, response, body) {
  10. if (error) throw new Error(error);
  11. console.log(body);
  12. });
  1. <?php
  2. $content_group_id = 1; // 内容库 ID
  3. $text_id = 2; // 内容 ID
  4. $url = "https://cloud.minapp.com/oserve/v1/content/{$content_group_id}/text/{$text_id}/";
  5. $param['title'] = 'TestUpdate';
  6. $ch = curl_init();
  7. $header = array(
  8. "Authorization: Bearer {$token}",
  9. 'Content-Type: application/json; charset=utf-8'
  10. );
  11. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  12. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  13. curl_setopt($ch, CURLOPT_URL, $url);
  14. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
  15. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($param));
  16. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  17. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  18. $res['response'] = curl_exec($ch); // 反馈结果
  19. $res['status_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 请求状态码
  20. curl_close($ch);

返回示例

  1. {
  2. "id": 2,
  3. "title": "Test Title",
  4. "group_id": 1,
  5. "categories": [],
  6. "created_at": 1519960085,
  7. "updated_at": 1519960085
  8. }

状态码说明

200: 修改成功

400: 提交数据为空;提交的数据都不合法

删除内容

接口

DELETE https://cloud.minapp.com/oserve/v1/content/:content_group_id/text/:text_id/

代码示例

  1. curl -X DELETE \
  2. -H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
  3. -H "Content-Type: application/json" \
  4. https://cloud.minapp.com/oserve/v1/content/1/text/1/
  1. var request = require("request");
  2. var options = { method: 'DELETE',
  3. url: 'https://cloud.minapp.com/oserve/v1/content/1/text/1/',
  4. headers:
  5. { 'Content-Type': 'application/json',
  6. Authorization: 'Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4' } };
  7. request(options, function (error, response, body) {
  8. if (error) throw new Error(error);
  9. console.log(body);
  10. });
  1. <?php
  2. $content_group_id = 1; // 内容库 ID
  3. $text_id = 1; // 内容 ID
  4. $url = "https://cloud.minapp.com/oserve/v1/content/{$content_group_id}/text/{$text_id}/";
  5. $ch = curl_init();
  6. $header = array(
  7. "Authorization: Bearer {$token}",
  8. 'Content-Type: application/json; charset=utf-8'
  9. );
  10. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  11. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  12. curl_setopt($ch, CURLOPT_URL, $url);
  13. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
  14. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  15. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  16. $res['response'] = curl_exec($ch); // 反馈结果
  17. $res['status_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 请求状态码
  18. curl_close($ch);

状态码说明

204: 删除成功