How to model file system operations with REST?

后端 未结 6 1345
挽巷
挽巷 2021-01-19 05:07

There are obvious counterparts for some of file systems\' basic operations (eg. ls and rm), but how would you implement not straightforwardly RESTf

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-19 05:49

    I dont believe any of the given answers are RESTful. Here is what I would do.

    For Copy:

    PUT /videos/johns_videos/copied-2-gigabyte-video.avi
    HOST: www.server.com
    Content-Location: /videos/johns_videos/2-gigabyte-video.avi
    [empty-body]
    

    PUT the content's at location (/videos/johns_videos/2-gigabyte-video.avi) at (/videos/johns_videos/copied-2-gigabyte-video.avi).

    A move would be a copy with a delete, to check for consistency between the copy and delete you will need to use a revision number which is given to you on the response of the PUT.

    PUT /videos/johns_videos/copied-2-gigabyte-video.avi
    HOST: www.server.com
    Content-Location: /videos/johns_videos/2-gigabyte-video.avi
    [empty-body]
    
        201 Created
        ETag: "3e32f5a1123afb12" (an md5 of the file)
        Location: /videos/johns_videos/copied-2-gigabyte-video.avi
        [empty-body]
    
    DELETE /videos/johns_videos/2-gigabyte-video.avi
    HOST: www.server.com
    If-Match: "3e32f5a1123afb12"
    [empty-body]
    
        204 No Content
        [empty-body]
    

    Why is this RESTful?

    • Does not append "move" or "copy" onto the URI (Which is RPC)
    • It uses PUT (POST is to append to a collection, the target URI is not fully known)
    • It does not use "commands" sent (e.g. XML instructions) which is RPC not REST.
    • No understanding of underline storage - The client does not care about hard/soft links or write-on-copy optimisations and should never know about them.

    Mike Brown

提交回复
热议问题