Evolution of the Web 1 Client Server 2 2 / 22 1 Client Server - - PowerPoint PPT Presentation

evolution of the web
SMART_READER_LITE
LIVE PREVIEW

Evolution of the Web 1 Client Server 2 2 / 22 1 Client Server - - PowerPoint PPT Presentation

E LIOM Tierless Web programming from the ground up Gabriel R ADANNE Jrme V OUILLON Vincent B ALAT Vasilis P APAVASILEIOU Evolution of the Web 1 Client Server 2 2 / 22 1 Client Server 2 2 / 22 1 Client Server DOM 2 2 / 22 1


slide-1
SLIDE 1

ELIOM

Tierless Web programming from the ground up

Gabriel RADANNE Jérôme VOUILLON Vincent BALAT Vasilis PAPAVASILEIOU

slide-2
SLIDE 2

Evolution of the Web Server Client

1 2

2 / 22

slide-3
SLIDE 3

Server Client

1 2

2 / 22

slide-4
SLIDE 4

Server Client

1 2

DOM

2 / 22

slide-5
SLIDE 5

Server Client

1 2

DOM

2 / 22

slide-6
SLIDE 6

Server Client

1 2

DOM

Client

2 / 22

slide-7
SLIDE 7

Server Client

1 2

DOM

Client

2 / 22

slide-8
SLIDE 8

Server Client

1 2

DOM

Client

Client Mobile

2 / 22

slide-9
SLIDE 9

Server Client

1 2

DOM

Client

Client Mobile

Untyped

2 / 22

slide-10
SLIDE 10

3 / 22

slide-11
SLIDE 11

Server Client

1 2

One language for everything

4 / 22

slide-12
SLIDE 12

Server Client

1 2

One language for everything Tierless languages: LINKS HOP UR/WEB ELIOM

4 / 22

slide-13
SLIDE 13

Server Client

1 2

One language for everything Tierless languages: LINKS HOP UR/WEB ELIOM

4 / 22

slide-14
SLIDE 14

The OCSIGEN project OCAML

JS_OF_OCAML

SERVER ELIOM

5 / 22

slide-15
SLIDE 15

The OCSIGEN project OCAML

JS_OF_OCAML

SERVER ELIOM

5 / 22

slide-16
SLIDE 16

The OCSIGEN project OCAML

JS_OF_OCAML

SERVER Language extension Libraries

5 / 22

slide-17
SLIDE 17

1

ELIOM’s language extension

2

Examples of libraries in ELIOM Widgets APIs

6 / 22

slide-18
SLIDE 18

Client and Server annotations

Server Client

Location annotations allow to use client and server code in the same program.

1 let%server s = ... 2 3 let%client c = ... 4 5 let%shared sh = ...

The program is sliced during compilation.

7 / 22

slide-19
SLIDE 19

Building fragments of client code inside server code

Fragments of client code can be included inside server code.

1 let%server x : int fragment = [%client 1 + 3 ]

8 / 22

slide-20
SLIDE 20

Building fragments of client code inside server code

Fragments of client code can be included inside server code.

1 let%server x : int fragment = [%client 1 + 3 ] 1 let%server y = [ ("foo", x) ; ("bar", [%client 2]) ]

8 / 22

slide-21
SLIDE 21

Accessing server values in the client

Injections allow to use server values on the client.

1 let%server s : int = 1 + 2 2 3 let%client c : int = ~%s + 1

9 / 22

slide-22
SLIDE 22

Everything at once

We can combine injections and fragments.

1 let%server x : int fragment = [%client 1 + 3 ] 2 3 let%client c : int = 3 + ~%x

10 / 22

slide-23
SLIDE 23

Everything at once

We can combine injections and fragments.

1 let%server x : int fragment = [%client 1 + 3 ] 2 3 let%client c : int = 3 + ~%x

Gabriel Radanne and Jérôme Vouillon and Vincent Balat ELIOM: A core ML language for Tierless Web programming

https://hal.archives-ouvertes.fr/hal-01349774

APLAS 2016

10 / 22

slide-24
SLIDE 24

1

ELIOM’s language extension

2

Examples of libraries in ELIOM Widgets APIs

11 / 22

slide-25
SLIDE 25

Counter widget

A button with a counter. HTML for the button is generated on the server. The button has a client-side state: the counter. When the button is pressed, the counter is incremented on the client. The button is parameterized by a client-side action.

12 / 22

slide-26
SLIDE 26

Counter widget

counter.eliom

1 let%server counter action = 2

let state = [%client ref 0 ] in

3

button

4

~button_type:‘Button

5

~a:[a_onclick

6

[%client fun _ ->

7

incr ~%state;

8

~%action !(~%state) ]]

9

[pcdata "Increment"]

13 / 22

slide-27
SLIDE 27

Counter widget

counter.eliom

1 let%server counter action = 2

let state = [%client ref 0 ] in

3

button

4

~button_type:‘Button

5

~a:[a_onclick

6

[%client fun _ ->

7

incr ~%state;

8

~%action !(~%state) ]]

9

[pcdata "Increment"]

counter.eliomi

1 val%server counter: (int -> unit) fragment -> Html.t

13 / 22

slide-28
SLIDE 28

Execution

1 let%server counter action = 2

let state = [%client ref 0 ] in

3

button

4

~button_type:‘Button

5

~a:[a_onclick

6

[%client fun _ ->

7

incr ~%state;

8

~%action !(~%state) ]]

9

[pcdata "Increment"] ELIOM code

1 let counter action = 2

let state = fragment1 in

3

button

4

~button_type:‘Button

5

~a:[a_onclick

6

(fragment2 state action)]

7

[pcdata "Increment"] Server code

1 let fragment1 = ref 0 2 3 let fragment2 state action = 4

fun _ ->

5

incr (injection state);

6

(injection action)

7

!(injection state) Client code

14 / 22

slide-29
SLIDE 29

Execution

Server Client

1 2

1 let counter action = 2

let state = fragment1 in

3

button

4

~button_type:‘Button

5

~a:[a_onclick

6

(fragment2 state action)]

7

[pcdata "Increment"] Server code

1 let fragment1 = ref 0 2 3 let fragment2 state action = 4

fun _ ->

5

incr (injection state);

6

(injection action)

7

!(injection state) Client code

14 / 22

slide-30
SLIDE 30

Execution

Server Client

1 2

1 let counter action = 2

let state = fragment1 in

3

button

4

~button_type:‘Button

5

~a:[a_onclick

6

(fragment2 state action)]

7

[pcdata "Increment"] Server code

1 let fragment1 = ref 0 2 3 let fragment2 state action = 4

fun _ ->

5

incr (injection state);

6

(injection action)

7

!(injection state) Client code

1 <button type=button onclick=...>Increment</button>

"state"→ "fragment1"; "action"→ ...

14 / 22

slide-31
SLIDE 31

Counter widget

What if we want to save the state of the counter on the server ?

counter.eliomi

1 val%server counter: (int -> unit) fragment -> Html.t

15 / 22

slide-32
SLIDE 32

Remote Procedure Calls

Remote Procedure Call (or RPC) is the action of a client calling the server without loading a new page and potentially getting a value back.

Server Client

16 / 22

slide-33
SLIDE 33

Remote Procedure Calls

A simplified RPC API:

rpc.eliomi

1 type%server (’i,’o) t 2 type%client (’i,’o) t = ’i -> ’o 3 4 val%server create : (’i -> ’o) -> (’i, ’o) t

17 / 22

slide-34
SLIDE 34

Remote Procedure Calls

A simplified RPC API:

rpc.eliomi

1 type%server (’i,’o) t 2 type%client (’i,’o) t = ’i -> ’o 3 4 val%server create : (’i -> ’o) -> (’i, ’o) t

An example using Rpc

1 let%server plus1 : (int, int) Rpc.t = 2

Rpc.create (fun x -> x + 1)

3 4 let%client f x = ~%plus1 x + 1

17 / 22

slide-35
SLIDE 35

Converters

Converters are a way to converts datatype between server and client. Here is a schematized signature for ~%, the injection operator:

1 type%shared serial (* A serialization format *) 2 3 type%server (’a, ’b) converter = { 4

serialize : ’a -> serial ;

5

deserialize : (serial -> ’b) fragment ;

6 } 7 8 (* Not a real type signature *) 9 val%client (~%) : 10

(’a, ’b) converter -> ’a (* server *) -> ’b (* client *)

18 / 22

slide-36
SLIDE 36

Implementing RPC with converters

1 type%server (’i,’o) t = { 2

url : string ;

3

handler: ’i -> ’o ;

4 } 5 6 type%client (’i, ’o) t = ’i -> ’o 7 8 let serialize t = serialize_string t.url 9 let deserialize x = 10

let url = deserialize_string x in

11

fun i -> AJAX.get url i

19 / 22

slide-37
SLIDE 37

Widget + Rpc

We can now use counter and Rpc together!

1 val%server save_counter : int -> unit 2 val%server counter : (int -> unit) fragment -> Html.t 3 4 let%server save_counter_rpc : (int, unit) Rpc.t = 5

Rpc.create save_counter

6 7 let%server widget_with_save : Html.t = 8

let f = [%client ~%save_counter_rpc] in

9

counter f

20 / 22

slide-38
SLIDE 38

Conclusion

Typesafe client-server communication The whole OCAML ecosystem Encapsulation and composition for widgets In the paper: Implementation of bigger examples and other APIs All of this is implemented and used: https://ocsigen.org

21 / 22

slide-39
SLIDE 39

Questions ?

slide-40
SLIDE 40

Remote Procedure Calls

Server Client

22 / 22

slide-41
SLIDE 41

Client-server reactive HTML

Server Client

DOM

22 / 22

slide-42
SLIDE 42

Bus/Multicast

Server Client Client

22 / 22