Building with Jamstack - wrangling APIs and UIs

A presentation at Smashing Meets in May 2020 in by Phil Hawksworth

Slide 1

Slide 1

BUILDING WITH JAMSTACK WRANGLING APIS AND UIS PHIL HAWKSWORTH @PHILHAWKSWORTH

Slide 2

Slide 2

Slide 3

Slide 3

Slide 4

Slide 4

LINES AND BOXES

Slide 5

Slide 5

yikes! YIYING ME MARK

Slide 6

Slide 6

JAMSTACK JAMSTACK JAMSTACK SOMETHING SOMETHING JAMSTACK PHIL, ALL THE TIME TO BE HONEST

Slide 7

Slide 7

ART IS ABOUT ASKING QUESTIONS, DESIGN IS ABOUT FINDING ANSWERS BRENDAN DAWES, I THINK

Slide 8

Slide 8

TECHNICAL DESIGN is DESIGN TOO

Slide 9

Slide 9

SIMPLICITY

Slide 10

Slide 10

https://unsplash.com/photos/KzGhmrQmB6I

Slide 11

Slide 11

https://unsplash.com/photos/KzGhmrQmB6I

Slide 12

Slide 12

fetch(‘https://nice.api.com/things.json’) .then(res =>” res.json()) .then(json =>” console.log(json));

Slide 13

Slide 13

BUILDING A SYSTEM e b n a c HARD

Slide 14

Slide 14

SOFTWARE ENGINEER TECHNICAL DIRECTOR DX ENGINEER

Slide 15

Slide 15

LINES AND BOXES

Slide 16

Slide 16

“VIEWING” SITES & “DOING” SITES

Slide 17

Slide 17

BUILDING WITH JAMSTACK WRANGLING APIS AND UIS PHIL HAWKSWORTH @PHILHAWKSWORTH

Slide 18

Slide 18

k c a t s m a j Fast and secure sites and apps delivered by pre-rendering files and serving them directly from a CDN, removing the requirement to manage or run web servers. https://jamstack.org

Slide 19

Slide 19

ASK FOR STUFF GET STUFF

Slide 20

Slide 20

“VIEWING” SITES & “DOING” SITES

Slide 21

Slide 21

ASK FOR STUFF GET STUFF DO ALL SORTS OF STUFF

Slide 22

Slide 22

MONOLITHS ONE CHOICE FOR ALL DISCIPLINES

Slide 23

Slide 23

https://unsplash.com/photos/KzGhmrQmB6I

Slide 24

Slide 24

Slide 25

Slide 25

SEPARATION OF CONCERNS

Slide 26

Slide 26

k c a t s jam MARKUP JAVASCRIPT API AS MUCH AS POSSIBLE, GENERATED IN ADVANCE USED AS A PROGRESSIVE ENHANCEMENT IN THE BROWSER OR ELSEWHERE

Slide 27

Slide 27

API USER INTERFACE

Slide 28

Slide 28

s s e l r e v r se ⚡ ⚡ k c a t s jam

Slide 29

Slide 29

API USER INTERFACE

Slide 30

Slide 30

API USER INTERFACE

Slide 31

Slide 31

API v8 v7 v6 v5.1 v5 v4.1 v4 v3 v2 v1 v8 USER INTERFACE v7 v6 v5 v4 v3 v2 v1

Slide 32

Slide 32

HOW ARE APIS AND UIS COUPLED? URL / SIGNATURE / RESPONSE

Slide 33

Slide 33

EXAMPLE

Slide 34

Slide 34

FINDTHAT.AT/CATCOUTURE EXAMPLE

Slide 35

Slide 35

{ “prod-cat-outfit-lion”: { “name”: “Cat lion mane costume”, “rrp”: “100.00”, “image”: “product-cat-lion.jpg”, “description”: “Dress your cat up as a lion and make it hate you while it looks cool.” }, … } inventory.json

Slide 36

Slide 36

EXAMPLE

Slide 37

Slide 37

API USER INTERFACE

Slide 38

Slide 38

const productViews = document.querySelectorAll(‘.product’); productViews.forEach(element =>” { fetch(/api/stock/${element.dataset.productId}) .then(response =>” response.json()) .then(data =>” { // update the UI based on the // levels of available stock }); }) shop.js

Slide 39

Slide 39

COUPLING — API ENDPOINT

Slide 40

Slide 40

API USER INTERFACE

Slide 41

Slide 41

API USER INTERFACE

Slide 42

Slide 42

API DECOUPLE WITH A PROXY USER INTERFACE

Slide 43

Slide 43

[[redirects]] from = “/api/stock/:id” to = “/.netlify/functions/stock?productId=:id” netlify.toml

Slide 44

Slide 44

[[redirects]] from = “/api/stock/:id” to = “https://other.api.com/stock?productId=:id” netlify.toml

Slide 45

Slide 45

HOW ARE APIS AND UIS COUPLED? URL / SIGNATURE / RESPONSE

Slide 46

Slide 46

├── ├── │ │ │ │ ├── ├── └── README.md api ├── data │ ├── catalogue.json │ └── inventory.json └── stock.js netlify.toml package.json src ├── css │ └── style.css ├── images ├── index.njk └── js └── shop.js

Slide 47

Slide 47

├── ├── │ │ │ │ ├── ├── └── README.md api ├── data │ ├── catalogue.json │ └── inventory.json └── stock.js netlify.toml package.json src ├── css │ └── style.css ├── images ├── index.njk └── js └── shop.js

Slide 48

Slide 48

├── ├── │ │ │ │ ├── ├── └── README.md api ├── data │ ├── catalogue.json │ └── inventory.json └── stock.js netlify.toml package.json src ├── css │ └── style.css ├── images ├── index.njk └── js └── shop.js

Slide 49

Slide 49

FINDTHAT.AT/CATCOUTURE/REPO EXAMPLE

Slide 50

Slide 50

UMM… “PRICE GOUGING?” SOME OF YOU, PERHAPS

Slide 51

Slide 51

ONE REPO ONE DEPLOYMENT

Slide 52

Slide 52

API UI

Slide 53

Slide 53

live API UI

Slide 54

Slide 54

live API UI

Slide 55

Slide 55

GIT WORKFLOWS ACROSS THE APPLICATION FTW

Slide 56

Slide 56

HOW ARE APIS AND UIS COUPLED? URL / SIGNATURE / RESPONSE

Slide 57

Slide 57

WRAPPING UP

Slide 58

Slide 58

LINES AND BOXES

Slide 59

Slide 59

STATIC FIRST ENHANCING IF REQUIRED

Slide 60

Slide 60

KEEP COUPLING LOOSE

Slide 61

Slide 61

THE API ECONOMY IS BOOMING

Slide 62

Slide 62

JAMSTACK & SERVERLESS ARE BEST FRIENDS

Slide 63

Slide 63

FINDTHAT.AT/LOLLY

Slide 64

Slide 64

FINDTHAT.AT/COMMENTS

Slide 65

Slide 65

FINDTHAT.AT/ELEVENTYONE

Slide 66

Slide 66

BOOK - MODERN WEB DEVELOPMENT ON THE JAMSTACK findthat.at/jamstackbook FREE CODE CAMP VIDEO findthat.at/jamstack/fcc JAMSTACK WHITEPAPER findthat.at/jamstack-whitepaper JAMSTACK COMMENTS EXAMPLE findthat.at/comments

Slide 67

Slide 67

FINDTHAT.AT/SMASHINGJAM THANKS @PHILHAWKSWORTH