Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Batch Operation

Theo Sun edited this page Nov 5, 2020 · 2 revisions

@odata/server support the OData V4.01 JSON batch format

POST /$batch HTTP/1.1
Host: localhost:50000
Content-Type: application/json
Content-Length: 1053

{
    "requests": [
        {
            "id": "1",
            "method": "POST",
            "url": "/Teachers",
            "body": {
                "name": "Jams T1",
                "profile": {
                    "title": "Professor L1"
                }
            }
        },
        {
            "id": "2",
            "method": "POST",
            "url": "/Classes",
            "body": {
                "name": "CS01",
                "desc": "Computer Scient (Basic)",
                "teacherOneId": 1
            }
        },
        {
            "id": "3",
            "method": "POST",
            "url": "/Students",
            "body": {
                "name": "John S1"
            }
        },
        {
            "id": "4",
            "method": "POST",
            "url": "/RelStudentClassAssignments",
            "body": {
                "studentId": 1,
                "classId": 1
            }
        },
        {
            "id": "5",
            "method": "GET",
            "url": "/RelViews"
        }
    ]
}

response:

{
    "responses": [
        {
            "status": 201,
            "id": "1",
            "headers": {
                "x-batch-request-id": "1",
                "x-batch-atom-group": "default",
                "Location": "http://localhost:50000/Teachers(1)"
            },
            "body": {
                "@odata.context": "http://localhost:50000/$metadata#Teachers/$entity",
                "@odata.id": "http://localhost:50000/Teachers(1)",
                "@odata.editLink": "http://localhost:50000/Teachers(1)",
                "tid": 1,
                "name": "Jams T1"
            }
        },
        {
            "status": 201,
            "id": "2",
            "headers": {
                "x-batch-request-id": "2",
                "x-batch-atom-group": "default",
                "Location": "http://localhost:50000/Classes(1)"
            },
            "body": {
                "@odata.context": "http://localhost:50000/$metadata#Classes/$entity",
                "@odata.id": "http://localhost:50000/Classes(1)",
                "@odata.editLink": "http://localhost:50000/Classes(1)",
                "cid": 1,
                "name": "CS01",
                "desc": "Computer Scient (Basic)",
                "teacherOneId": 1
            }
        },
        {
            "status": 201,
            "id": "3",
            "headers": {
                "x-batch-request-id": "3",
                "x-batch-atom-group": "default",
                "Location": "http://localhost:50000/Students(1)"
            },
            "body": {
                "@odata.context": "http://localhost:50000/$metadata#Students/$entity",
                "@odata.id": "http://localhost:50000/Students(1)",
                "@odata.editLink": "http://localhost:50000/Students(1)",
                "sid": 1,
                "name": "John S1"
            }
        },
        {
            "status": 201,
            "id": "4",
            "headers": {
                "x-batch-request-id": "4",
                "x-batch-atom-group": "default",
                "Location": "http://localhost:50000/RelStudentClassAssignments(1)"
            },
            "body": {
                "@odata.context": "http://localhost:50000/$metadata#RelStudentClassAssignments/$entity",
                "@odata.id": "http://localhost:50000/RelStudentClassAssignments(1)",
                "@odata.editLink": "http://localhost:50000/RelStudentClassAssignments(1)",
                "uuid": 1,
                "studentId": 1,
                "classId": 1
            }
        },
        {
            "status": 200,
            "id": "5",
            "headers": {
                "x-batch-request-id": "5",
                "x-batch-atom-group": "default"
            },
            "body": {
                "@odata.context": "http://localhost:50000/$metadata#RelViews",
                "value": [
                    {
                        "@odata.id": "http://localhost:50000/RelViews(1)",
                        "@odata.editLink": "http://localhost:50000/RelViews(1)",
                        "uuid": 1,
                        "studentName": "John S1",
                        "className": "CS01",
                        "teacherName": "Jams T1"
                    }
                ]
            }
        }
    ]
}