Skip to content

进阶

批量请求

简单批量请求

请求

php
curl \
    -X 'POST'
    -H 'X-AUTH-TOKEN=...' \
    -H 'Accept=application/vnd.edusoho.v2+json' \
    -F 'batch=[{"method":"GET", "relative_url":"/course_sets"},{"method":"GET", "relative_url":"/courses?limit=50"}]' \
    http://demo.edusoho.com/api/batch

响应

[
    { "code": 200,
      "body": {\"data\": [{…}]},
    { "code": 200,

      "body":{\"data\": [{…}]}
]

包含多种方法的批量请求

php
curl \
    -X 'POST'
    -H 'X-AUTH-TOKEN=...' \
    -H 'Accept=application/vnd.edusoho.v2+json' \
    -F 'batch=[
          {
            "method":"POST",
            "relative_url":"/courses/1/members",
            "body":"ads=%5B%7B%22name%22%3A%22test_ad%22%2C%22billing_entity_id%22%3A111200774273%7D%5D"
          },
          {
            "method":"GET",
            "relative_url":"/course_sets?title=ad"
          }
        ]' \
    http://demo.edusoho.com/api/batch

响应

[
    { "code": 200,
      "body": {\"id\": [{…}]},
    { "code": 200,

      "body":{\"data\": [{…}]}
]