Slide 1

Slide 1 text

Vue & REST Patterns Sultan Iman @imanhodjaev https://t.me/FullTimeVue

Slide 2

Slide 2 text

How people do it?

Slide 3

Slide 3 text

Naive approach

Slide 4

Slide 4 text

Route guards

Slide 5

Slide 5 text

Fetch components https://jsfiddle.net/adamwathan/xov6ksvd/ fetch-data updates its slots once request completed

Slide 6

Slide 6 text

https://jsfiddle.net/adamwathan/xov6ksvd/

Slide 7

Slide 7 text

Using Vuex It might become a mess over time

Slide 8

Slide 8 text

Organize Use Repository pattern https://martinfowler.com/eaaCatalog/repository.html

Slide 9

Slide 9 text

How it usually looks in Java

Slide 10

Slide 10 text

The goal Vuex actions must only know what to call and what arguments to pass and how to maintain the state

Slide 11

Slide 11 text

Makes it easier to unit test (mock, spy etc.)

Slide 12

Slide 12 text

Demo

Slide 13

Slide 13 text

Improving May be use of error boundaries will help to improve user experience

Slide 14

Slide 14 text

Hmmm how do checkResponse and post work? https://gist.github.com/imanhodjaev/88c24066e7bfd283f64145eef7b19e7f https://gist.github.com/imanhodjaev/86042197648902cd9514f9b2ef6b8307

Slide 15

Slide 15 text

Links https://medium.com/@imanhodjaev/handling-api-calls-in-vue-cf39747656ba https://medium.com/@lachlanmiller_52885/a-pattern-to-handle-ajax-requests-in-vuex-2d69bc2f8984 https://medium.com/js-dojo/4-ajax-patterns-for-vue-js-apps-add915fc9168 https://itnext.io/anyway-heres-how-to-do-ajax-api-calls-with-vue-js-e71e57d5cf12 https://medium.com/@krzychukosobudzki/repository-design-pattern-bc490b256006 https://martinfowler.com/eaaCatalog/repository.html

Slide 16

Slide 16 text

Thanks! ❤