- RESTful Web API Design with Node.js 10
- Valentin Bojinov
- 255字
- 2021-08-27 18:37:24
Principle 2 – Each resource is identifiable by a unique identifier
Since the internet contains so many different resources, they all should be accessible via URIs and should be identified uniquely. Furthermore, the URIs can be in a human-readable format, despite the fact that their consumers are more likely to be software programs rather than ordinary humans.
Human-readable URIs keep data self-descriptive and ease further development against it. This helps you to keep the risk of logical errors in your programs to a minimum.
Here are a few sample examples of such URIs representing different resources in a catalog application:
- http://www.mycatalog.com/categories/watches
- http://www.mycatalog.com/categories/watches?collection=2018
- http://www.mycatalog.com/categories/watches/model-xyz/image
- http://www.mycatalog.com/categories/watches/model-xyz/video
- http://www.mycatalog.com/archives/2017/categories/watches.zip
These human-readable URIs expose different types of resources in a straightforward manner. In the preceding example URIs, it is quite clear the data is items in a catalog, which are categorized watches. The first link shows all the items in the category. The second shows only the ones that are part of the 2018 collection. Next is a link pointing to the image of the item, followed by a link to a sample video. The last link points to a resource containing items from the previous collection in a ZIP archive. The media types served per each URI are rather easy to identify, with the assumption that the data format of an item is either JSON or XML, so we can easily map the media type of a self-described URL to one of the following:
- JSON or XML documents describing the items
- Images
- Videos
- Binary archive documents
- Modular Programming with Python
- Scala Design Patterns
- 樂高機器人設計技巧:EV3結構設計與編程指導
- 看透JavaScript:原理、方法與實踐
- Visual Basic程序設計(第3版):學習指導與練習
- Java應用開發技術實例教程
- Hands-On Microservices with Kotlin
- Java編程技術與項目實戰(第2版)
- 用戶體驗可視化指南
- OpenResty完全開發指南:構建百萬級別并發的Web應用
- Mastering C++ Multithreading
- Python從入門到精通(第3版)
- Illustrator CS6設計與應用任務教程
- 小程序從0到1:微信全棧工程師一本通
- 奔跑吧 Linux內核