REST - alexanderteplov/computer-science GitHub Wiki

REST (REpresentational State Transfer)

REST is a software architectural style that defines constraints for organizing web systems.

REST constraints (defines RESTfull services)

  • Client-server architecture
  • Statelessness
  • Cacheability
  • Layered system
  • Code on demand (optional)
  • Uniform interface

Richardson Maturity Model

  1. Level 0

    One URL, one method

  2. Level 1 - Resources

    Multiple URLs (resources), one method

  3. Level 2 - HTTP Verbs

    Multiple URLs, multiple methods (HTTP Verbs, HTTP semantic methods)

  4. Level 3 - Hypermedia Controls or HATEOAS (Hypertext As The Engine Of Application State)

    All from level 2, plus an ability API of self-documenting (GET requests can return a list of URLs with possible actions)

CRUD

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.

Idempotent HTTP methods

OPTIONS, GET, HEAD, PUT, DELETE

Safe HTTP methods

OPTIONS, GET, HEAD

Safe HTTP methods could be cashed (by browser, proxy, gateway server).

Contract First

Pros

  • parallel work
  • possible code generation (stubs, mocks)
  • higher level of abstraction, less implementation-specific details
  • better design and easier code reusing

Cons

  • more effort on start
  • extra costs to maintaining and updating a contract

Code First

Pros

  • easy to get a contract with generation from code
  • auto-sync between contract and code with contract generation

Cons

  • no parallel work
  • more chaotic contract
  • higher coupling with implementation details (programming language, platform)

Links

⚠️ **GitHub.com Fallback** ⚠️