<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Naming your REST endpoints

      How to name your REST endpoint? How does your endpoint look? Are there any guidelines or best practices? How to name your endpoints?

      A short introduction

      We often use APIs to implement CRUD operations, or most APIs start like this, but all of them evolve over time.
      CRUD is an acronym that stands for Create, Read, Update, Delete. And these are all the operations that you can apply to a specific resource.

      Let’s take childish example, and say you need to manage pets for a veterinary cabinet and you are interested in cats:

      /api/getAllCats– wouldn’t /api/cats be easier to remember?
      /api/newCat – how about /api/catsand use POST as HTTP Verb?
      /api/getBlackCats– why should you have a different endpoint? /api/cats?color=blackwill have the same path, but the parameter value will change an get you a lot of flexibility
      /api/getCatsOwners– how about /api/cats/{id}/owners– this way you will know exactly to which cat you are reffering. The one with the {id} in the URL path.
      /api/getHungerLevel– hunger level of…? cat? which cat? maybe is youru hunger level?

      If you look at the endpoints, are very hard to remember, and once you add more operations, it will be even harder to remember and harder to manage. Plus, you have no reason to include get{something} in the endpoint or have tons of endpoints. The HTTP verb will be the one that tells what operation you are doing. Either is a GET, a POST or something else. KISS, as in code, also applies here. And more than that, we need to keep in mind that we need to leverage the underlying protocol as much as we can.

      In my opinion, an endpoint in a REST API should be self-explanatory. Just by looking at the URL, you( and the server) should be able to tell what is the resource it handles without needing a manual.

      One ot the things REST is trying to do, is to remove the uglyness we all dealt with in SOAP. SOAP exposed a set of operations in a WSDL file, and to ‘call’ those operations we made a single type of call(POST or GET). REST is trying to get rid of that paradigm and get us closer to the underlying protocol.

      Luckily, if you are nostalgic(or not) we have tools like Swagger and the Open API standard to help us with the documentation, but even so, and URL should express intent in the ‘eyes’ of the consumer.

      COOL URI’s don’t change.

      Let’s look at the 2 endpoints that you will need in a REST API.

      An endpoint for the collection

      /api/cats

      This will allow you 2 operations:

      • retrieve the collection by HTTP GET (a read)
      • Create a new resource by using HTTP POST (a create)

      An endpoint for a specific item

      /api/pets/{id}

      This will allow you 4 operations:

      • retrieve the item by using HTTP GET(a read)
      • update an existing resource by using HTTP PUT(an update) or HTTP PATCH
      • delete and existing resource by using HTTP DELETE(a delete)

      Related/hierarchical resources

      Any hierarchical resource can be represented further in the URL path, but the convention remains, and applies down in the hierarchy.

      Let’s take the example of wanting to represent the owners of a specific cat:

      /api/cats/{id}/owners

      Looking at this URL we realize that in the cats collection, we are interested in the specific {id} of the cats, and from this specific cat, we want the owners collection.

      When we obtain the list of owners, we might be interest to obtain a specific one, and we can take another step : /api/cats/{id}/owners/{ownerid}

      You are not forced to model your data and store it in the database according to the endpoints, or the other way a round. Remember, in REST, you work with representations of resources, and those representations are handled by you. At the server level, for more decoupling and simplicity, you should use DTOs to transform or aggregate data.

      Takeaways

      • Name your endpoints in such a way to have meaning for the business and your consumers
      • You don’t need a different endpoint to represent a new operation. You can give meaning to your request by using the right HTTP verb
      • You can use GET, POST to the same endpoint /api/cats : the end result will be different.
      • you need two endpoints to represent major operations on a resource
      • Variations of specific resources can be represented as parameters in the query string, not different endpoints.

      In conclusion, it is up to you how you shape your endpoints. There is no constraint in this. As long as it makes sense for the business, expresses the intent, and is specific enough.

      The meaning for each request/response should be added by using the right HTTP Verbs, headers and status codes.

      posted @ 2020-11-26 10:15  句幽  閱讀(323)  評論(1)    收藏  舉報
      主站蜘蛛池模板: 国产亚洲第一精品| h无码精品3d动漫在线观看| 国产精品天干天干综合网| 国产99视频精品免费专区| 奶头又大又白喷奶水av| 国产午夜精品久久一二区| 日韩精品成人一区二区三| 青青草无码免费一二三区| 亚洲av日韩av一区久久| 日本不卡的一区二区三区| 最近免费中文字幕大全免费版视频 | 亚洲精品岛国片在线观看| 99久久综合精品五月天| 天堂久久天堂av色综合| 中文字幕无码av不卡一区| 日韩熟妇中文色在线视频| 日产国产一区二区不卡| 国产精品国语对白露脸在线播放| 欧产日产国产精品精品| 亚洲永久视频| 日本偷拍自影像视频久久| 国产va在线观看免费| 国产一区二区丰满熟女人妻| 精品国产免费一区二区三区香蕉| 国产精品普通话国语对白露脸| 亚洲无人区码一二三四区| 少妇又紧又色又爽又刺激视频| 欧美日本激情| 中文字幕久久熟女蜜桃| 日韩人妻精品中文字幕| 精品人妻少妇一区二区三区| 国产精品一区高清在线观看| 中文字幕亚洲男人的天堂网络 | 一本大道色婷婷在线| 国产av一区二区三区久久| 精品福利视频一区二区三区| 在线国产精品中文字幕| 久久AV中文综合一区二区| 青青青久热国产精品视频| 国产精品毛片一区二区| 免费无码一区二区三区蜜桃|