Call a Server-side Method on a Resource in a RESTful Way

后端 未结 8 1756
小蘑菇
小蘑菇 2020-12-02 03:14

Keep in mind I have a rudimentary understanding of REST. Let\'s say I have this URL:

http://api.animals.com/v1/dogs/1/

And now, I want to m

8条回答
  •  盖世英雄少女心
    2020-12-02 04:14

    If we assume Barking is an inner / dependent / sub resource which the consumer can act on, then we could say:

    POST http://api.animals.com/v1/dogs/1/bark
    

    dog number 1 barks

    GET http://api.animals.com/v1/dogs/1/bark
    

    returns the last bark timestamp

    DELETE http://api.animals.com/v1/dogs/1/bark
    

    doesn't apply! so ignore it.

提交回复
热议问题