|
1 |
| -<!doctype html> |
| 1 | +<!DOCTYPE html> |
2 | 2 | <html lang="">
|
3 |
| -<head> |
4 |
| -<meta charset="utf-8"> |
5 |
| -<title>hello webrpc (js)</title> |
6 |
| -<meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
7 |
| -<link rel="icon" href="" /> |
8 |
| -<script charset="utf-8" src="./client.gen.js" type="text/javascript"></script> |
9 |
| -<style> |
10 |
| -</style> |
11 |
| -</head> |
12 |
| -<body> |
13 |
| - |
14 |
| -<div id="app"> |
15 |
| - <h1>hello webrpc, simple JS app -- open your console</h1> |
16 |
| -</div> |
| 3 | + <head> |
| 4 | + <meta charset="utf-8" /> |
| 5 | + <title>hello webrpc (js)</title> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 7 | + <link rel="icon" href="" /> |
| 8 | + <script |
| 9 | + charset="utf-8" |
| 10 | + src="./client.gen.js" |
| 11 | + type="text/javascript" |
| 12 | + ></script> |
| 13 | + <style></style> |
| 14 | + </head> |
| 15 | + <body> |
| 16 | + <div id="app"> |
| 17 | + <h1>hello webrpc, simple JS app -- open your console</h1> |
| 18 | + </div> |
17 | 19 |
|
18 |
| -<script> |
19 |
| - const svcFetch = window.fetch.bind(window) |
20 |
| - let svc = new ExampleService('http://127.0.0.1:4242', svcFetch) |
| 20 | + <script> |
| 21 | + let svc = new ExampleService("http://127.0.0.1:4242", fetch); |
21 | 22 |
|
22 |
| - // Expecting "true" |
23 |
| - console.log('[A] webrpc -- calling Ping() rpc method (expecting true):') |
| 23 | + // Expecting "true" |
| 24 | + console.log("[A] webrpc -- calling Ping() rpc method (expecting true):"); |
24 | 25 |
|
25 |
| - svc.ping().then(resp => { |
26 |
| - console.log('[A]', {resp}) |
27 |
| - }).catch(err => { |
28 |
| - console.log('[A]', {err}) |
29 |
| - }) |
| 26 | + svc |
| 27 | + .ping() |
| 28 | + .then((resp) => { |
| 29 | + console.log("[A]", { resp }); |
| 30 | + }) |
| 31 | + .catch((err) => { |
| 32 | + console.log("[A]", { err }); |
| 33 | + }); |
30 | 34 |
|
31 |
| - // Expecting an error |
32 |
| - console.log('[B] webrpc -- calling GetUser() rpc method of an unknown user (expecting a 404):') |
| 35 | + // Expecting an error |
| 36 | + console.log( |
| 37 | + "[B] webrpc -- calling GetUser() rpc method of an unknown user (expecting a 404):" |
| 38 | + ); |
33 | 39 |
|
34 |
| - svc.getUser({userID: 911}).then(resp => { |
35 |
| - console.log('[B]', resp.user) |
36 |
| - }).catch(err => { |
37 |
| - console.log('[B]', {err}) |
38 |
| - }) |
| 40 | + svc |
| 41 | + .getUser({ userID: 911 }) |
| 42 | + .then((resp) => { |
| 43 | + console.log("[B]", resp.user); |
| 44 | + }) |
| 45 | + .catch((err) => { |
| 46 | + console.log("[B]", { err }); |
| 47 | + }); |
39 | 48 |
|
40 |
| - // Expecting some user data |
41 |
| - console.log('[C] webrpc -- calling GetUser() rpc method (expecting User object):') |
| 49 | + // Expecting some user data |
| 50 | + console.log( |
| 51 | + "[C] webrpc -- calling GetUser() rpc method (expecting User object):" |
| 52 | + ); |
42 | 53 |
|
43 |
| - // svc.GetUser({userID: 966}).then(({ user }) => { |
44 |
| - svc.getUser({userID: 966}).then(resp => { |
45 |
| - const user = resp.user |
46 |
| - console.log('[C]', {user}) |
47 |
| - console.log('[C] welcome user ID', user.id, 'with username', user.USERNAME) |
48 |
| - }).catch(err => { |
49 |
| - console.log('[C]', {err}) |
50 |
| - }) |
51 |
| - |
52 |
| - |
53 |
| -</script> |
54 |
| - |
55 |
| -</body> |
| 54 | + // svc.GetUser({userID: 966}).then(({ user }) => { |
| 55 | + svc |
| 56 | + .getUser({ userID: 966 }) |
| 57 | + .then((resp) => { |
| 58 | + const user = resp.user; |
| 59 | + console.log("[C]", { user }); |
| 60 | + console.log( |
| 61 | + "[C] welcome user ID", |
| 62 | + user.id, |
| 63 | + "with username", |
| 64 | + user.USERNAME |
| 65 | + ); |
| 66 | + }) |
| 67 | + .catch((err) => { |
| 68 | + console.log("[C]", { err }); |
| 69 | + }); |
| 70 | + </script> |
| 71 | + </body> |
56 | 72 | </html>
|
0 commit comments