Slide 1

Slide 1 text

HTTP METHODS IS IDEMPOTENCE AN ILLNESS? Created by Maciej Rząsa

Slide 2

Slide 2 text

HTTP REQUEST G E T / u s e r s H T T P / 1 . 1 A c c e p t ­ E n c o d i n g : g z i p ; q = 1 . 0 , d e f l a t e ; q = 0 . 6 , i d e n t i t y ; q = 0 . 3 A c c e p t : * / * U s e r ­ A g e n t : R u b y C o n n e c t i o n : c l o s e H o s t : e x a m p l e . c o m

Slide 3

Slide 3 text

HTTP METHOD PROPERTIES safe methods no resource modifications idempotent methods called multiple leaves resource in the same state safe methods are idempotent

Slide 4

Slide 4 text

SAFE GET retreive data identified by URL HEAD like GET but without body OPTIONS available communication options, e.g. CORS

Slide 5

Slide 5 text

IDEMPOTENT PUT apply a new version of the resource (new or existing) PATCH apply a set of changes to the resource DELETE delete the resource

Slide 6

Slide 6 text

UNSAFE AND NON- IDEMPOTENT POST process the body with the resource

Slide 7

Slide 7 text

EXAMPLES view a page (and record a page view) change an email of a user make a bank transfer buy a book increment a counter enable/disable option: toggle?

Slide 8

Slide 8 text

SUMMARY NEVER change state using GET remember that PUT should be idempotent use idempotent methods where possible (TBC)