REST - alexanderteplov/computer-science GitHub Wiki
REST is a software architectural style that defines constraints for organizing web systems.
- Client-server architecture
- Statelessness
- Cacheability
- Layered system
- Code on demand (optional)
- Uniform interface
-
One URL, one method
-
Multiple URLs (resources), one method
-
Multiple URLs, multiple methods (HTTP Verbs, HTTP semantic methods)
-
All from level 2, plus an ability API of self-documenting (GET requests can return a list of URLs with possible actions)
There is a popular mapping of general computer science operations (mostly applicable to databases) to HTTP methods.
| CRUD | HTTP Verb |
|---|---|
| CREATE | POST |
| REQUEST | GET |
| UPDATE | PUT |
| DELETE | DELETE |
In this set of methods POST semantically differs from others in IETF specification, so we can meet an approach of usage PUT as CREATE too.
OPTIONS, GET, HEAD, PUT, DELETE
OPTIONS, GET, HEAD
Safe HTTP methods could be cashed (by browser, proxy, gateway server).
- parallel work
- possible code generation (stubs, mocks)
- higher level of abstraction, less implementation-specific details
- better design and easier code reusing
- more effort on start
- extra costs to maintaining and updating a contract
- easy to get a contract with generation from code
- auto-sync between contract and code with contract generation
- no parallel work
- more chaotic contract
- higher coupling with implementation details (programming language, platform)