How an RPC-style example would look modelled in a resource-centric style

安稳与你 提交于 2019-12-02 12:29:22

You may have read these two great books:

Back to your questions. The more practical way of thinking or applying REST as the starting point (at least it works for me) is to think in the following ways:

1) Use only HTTP ‘GET/POST/PUT/DELETE’ as the way to model your domain ‘actions’ . Just like when you dealing with database, all your actions are mapped to CURD.

2) URI/URL is to identify resources only. Should never have any ‘actions’ in your URI.

3) The data exchanged should be in the body of the HTTP messages. Just to simplify the discussions, not getting into how to model the data itself

Here is what comes to my mind. I’m sure that there are better ways to model what you have but it should be around the same principles☺ E.g. how the URL patterns look like is all depending on your application domain and what makes sense between the client and the backend.

To model ‘get jobs’:

  • HTTP: GET
  • URL: ~/contractors/[plumberID]/jobs/

To model, job search:

  • HTTP: GET
  • URL: ~/jobs/?[some search params]/

To model assign the job to user:

  • HTTP: PUT
  • URL: ~/contractors/[plumberID]/assignments/[jobID]

There are some differences in using PUT vs POST, you can search around.

Hope this help.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!