Restful way for deleting a bunch of items

后端 未结 8 1106
栀梦
栀梦 2020-12-04 05:26

In wiki article for REST it is indicated that if you use http://example.com/resources DELETE, that means you are deleting the entire collection.

If you use http://ex

8条回答
  •  遥遥无期
    2020-12-04 05:47

    Here's what Amazon did with their S3 REST API.

    Individual delete request:

    DELETE /ObjectName HTTP/1.1
    Host: BucketName.s3.amazonaws.com
    Date: date
    Content-Length: length
    Authorization: authorization string (see Authenticating Requests (AWS Signature Version 4))
    

    Multi-Object Delete request:

    POST /?delete HTTP/1.1
    Host: bucketname.s3.amazonaws.com
    Authorization: authorization string
    Content-Length: Size
    Content-MD5: MD5
    
    
    
        true
        
             Key
             VersionId
        
        
             Key
        
        ...
               
    

    But Facebook Graph API, Parse Server REST API and Google Drive REST API go even further by enabling you to "batch" individual operations in one request.

    Here's an example from Parse Server.

    Individual delete request:

    curl -X DELETE \
      -H "X-Parse-Application-Id: ${APPLICATION_ID}" \
      -H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
      https://api.parse.com/1/classes/GameScore/Ed1nuqPvcm
    

    Batch request:

    curl -X POST \
      -H "X-Parse-Application-Id: ${APPLICATION_ID}" \
      -H "X-Parse-REST-API-Key: ${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.parse.com/1/batch
    

提交回复
热议问题