Web service differences between REST and RPC

后端 未结 9 1303
情歌与酒
情歌与酒 2020-12-07 06:54

I have a web service that accepts JSON parameters and have specific URLs for methods, e.g.:

http://IP:PORT/API/getAllData?p={JSON}

This is

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 07:14

    This is how I understand and use them in different use cases:

    Example: Restaurant Management

    use-case for REST: order management

    - create order (POST), update order (PATCH), cancel order (DELETE), retrieve order (GET)
    - endpoint: /order?orderId=123
    

    For resource management, REST is clean. One endpoint with pre-defined actions. It can be seen a way to expose a DB (Sql or NoSql) or class instances to the world.

    Implementation Example:

    class order:
        on_get(self, req, resp): doThis.
        on_patch(self, req, resp): doThat.
    

    Framework Example: Falcon for python.

    use-case for RPC: operation management

    - prepare ingredients: /operation/clean/kitchen
    - cook the order: /operation/cook/123
    - serve the order /operation/serve/123
    

    For analytical, operational, non-responsive, non-representative, action-based jobs, RPC works better and it is very natural to think functional.

    Implementation Example:

    @route('/operation/cook/')
    def cook(orderId): doThis.
    
    @route('/operation/serve/')
    def serve(orderId): doThat.
    

    Framework Example: Flask for python

提交回复
热议问题