How to move a REST resource?

后端 未结 3 2070
无人共我
无人共我 2021-02-05 23:42

I\'m trying to move a resource from /buckets/1 to /buckets/2 such that:

Initial state

  • /buckets/1 = foo
  • /buckets/2 = HT
3条回答
  •  逝去的感伤
    2021-02-06 00:30

    1. GET /buckets/1
    2. DELETE /buckets/1
    3. PUT /buckets/2 {data returned by #1}

    That doesn't make the server 301, though. The alternative would be to use the WebDAV MOVE method, i.e. by creating your own @MOVE annotation using the @HttpMethod annotation:

    import ...;
    
    @Target({ElementType.METHOD})
    @Retention(RetentionPolicy.RUNTIME)
    @HttpMethod("MOVE")
    public @interface MOVE {}
    

    but doing so breaks REST's architectural principle of using HTTP as a uniform interface (RESTful Java).

提交回复
热议问题