Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Pixelpillow College Tour - HTTP APIs

Joël Cox
October 18, 2023

Pixelpillow College Tour - HTTP APIs

Joël Cox

October 18, 2023
Tweet

More Decks by Joël Cox

Other Decks in Programming

Transcript

  1. HTTP is een… • URL – h tt ps://google.com/search?q=lmgt fy

    • Methode – POST, PATH, DELETE • Headers – Content-Type: “applica ti on/json” • Body – { “foo”: “bar” } • Status code – 200 OK
  2. RESTful Stateless – Geen afhankelijkheden tussen opvolgende requests. Decoupled –

    Geen aannames over gebruik door een client. Cacheable – En dus snel Uniform – Voorspelbaar!
  3. RESTful requests GET /api/posts ! 200 OK POST /api/posts !

    201 Created GET /api/posts/1 ! 200 OK PATCH /api/posts/12 ! 200 OK DELETE /api/posts/12 ! 410 Gone
  4. RESTful is niet genoeg… Geen standaard, slechts principes 👎 Geen

    ondersteuning voor “ac ti es” 🤔 Rela ti onele data is las ti g. 😭
  5. JSON-API: Best of REST Een standaard! Vanuit de prak ti

    jk ( fi lters, meta data, etc.) Rela ti es via links en included
  6. { "data": [ { "type": "articles", "id": "1", "attributes": {

    “title": "JSON:API paints my bikeshed!" }, "relationships": { "author": { "links": { "self": "http://example.com/articles/1/relationships/author", "related": "http://example.com/articles/1/author" }, "data": { "type": "people", "id": "9" } }, "comments": { "links": { "self": "http://example.com/articles/1/relationships/comments", "related": "http://example.com/articles/1/comments" }, "data": [ { "type": "comments", "id": "5" }, { "type": "comments", "id": "12" } ] } }, "links": { "self": "http://example.com/articles/1" } }], "included": [{ "type": "people", "id": "9", "attributes": { "firstName": "Dan", "lastName": "Gebhardt", "twitter": "dgeb" },
  7. { "data": [ { "type": "articles", "id": "1", "attributes": {

    "title": "JSON:API paints my bikeshed!" }, "relationships": { "author": { "links": { "self": "http://example.com/articles/1/relationships/author", "related": "http://example.com/articles/1/author" }, "data": { "type": "people", "id": "9" } }, "comments": { "links": { "self": "http://example.com/articles/1/relationships/comments", "related": "http://example.com/articles/1/comments" }, "data": [ { "type": "comments", "id": "5" }, { "type": "comments", "id": "12" } ] } }, "links": { "self": "http://example.com/articles/1" } }], "included": [{ "type": "people", "id": "9", "attributes": { "firstName": "Dan", "lastName": "Gebhardt", "twitter": "dgeb" },
  8. JSON:API hee ft geen… Geen ondersteuning voor “ac ti es”

    🤔 (bijv. het favoriten van een resource) Is niet self-documen ti ng… 📚
  9. Can’t have your cake and eat it too. Paradigma sluit

    niet aan bij onze manier van backends bouwen.