1 of 24

Modern JavaScript and REST

The language of the web got a lot better

2 of 24

Who are we?

Dušan Mlađenović

Developer/consultant at Bouvet

Developer with huge passion for functional programming, javascript and related languages.

�Contact at: dusan.mladenovic@bouvet.no

Marius Kalvø

Developer/consultant at Bouvet

Interest in backend and devOps, delivery of software

Contact at: marius.kalvo@bouvet.no

3 of 24

Vil Vite WIFI

SSID: VIS-gjest

Password: visdet2019

4 of 24

Our sponsors

Bouvet is a Norwegian consultant firm with over 1000 employees, assisting businesses in all areas of IT, communication, and business development.

Customers (in Bergen) includes Equinor, TV2, Statkraft, Sparebanken Vest, and Bergen kommune, among others.

http://www.bouvet.no/https://www.bouvet.no/bouvet-deler

VIS bidrar til at samfunnsutfordringer løses effektivt, og at kunnskap og ideer kommer raskt til nytte. Forskere, gründere og etablert næringsliv kommer til VIS med utfordringer og ideer som vi videreutvikler sammen.

https://www.visinnovasjon.no

5 of 24

6 of 24

Nerdschool resources

  • All presentations are public on Google Docs
  • Git repository pr workshop
  • Static web page with info (how to come prepared)
  • Meetup for signup and feedback

7 of 24

ECMAScript 20XX

8 of 24

ECMA-what?

  • ECMAScript 5 (old) vs ECMAScript 20XX (new)
  • Main new(ish) features:
    • let / const
    • template strings
    • default parameters
    • arrow functions
    • modules
    • classes
    • For...of loop
    • Spread operator
    • Promises
    • async / await

9 of 24

let / const

  • var is scoped to the nearest function block, which can make variables awkward to handle in inner scopes
  • let is scoped to the nearest enclosing block, which can be smaller than the function block. This makes scoping of let variables easier to handle

10 of 24

Template strings

  • Easier way to handle strings with dynamic data

11 of 24

Default parameters

Now possible to define a default value for a parameter if it’s not set explicitly

12 of 24

Arrow functions

  • Syntax sugar for writing functions
  • Can return directly

13 of 24

Modules

  • A file is a module
  • Importing and exporting
  • Encapsulation
  • Before ES6: no modules (just chaos), then AMD (RequireJS) and CommonJS(node)

14 of 24

Classes

  • Syntactical sugar for �JavaScript’s prototype interface
  • It’s just a function
  • Constructor
  • Methods
  • Properties (get/set)

15 of 24

Classes continued

  • Static methods
  • Easier to handle inheritance

16 of 24

Asynchronous operations

  • Better APIs for writing async code
  • async / await does not replace Promises but use Promises

17 of 24

How to use all these awesome features?

  • Modern browsers and modern JS runtimes support most of the new features
  • If a JS runtime does not support the features you are using you can
    • Transpile - Use a tool to rewrite your code so that the JS runner understands it
    • Polyfill - A unit of code that fills the gap of missing native support for some functionality

18 of 24

REST

19 of 24

What is REST?

20 of 24

Why REST?

  • It’s native to the web - no fuzz!
  • All serious languages supports it - no need to learn a “new way”
  • Excellent for connecting systems cross-platform or cross-language
  • Easy to learn
  • Easy to get up and running fast

21 of 24

Working with resources

  • A resource is an entity we base REST operations around. E.x.: book
  • The URL reflects our resource
  • The HTTP verb reflects what kind of operation we want
  • The data for the operation is in the request URL, header, and/or body.

22 of 24

Assignments

23 of 24

Exercises

24 of 24

Next meetup

Risk-based testing

8/10/2019

http://www.meetup.com/Bergen-Nerdschool/

Remember to sign up! (It’s really important!)