Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _examples/hello-webrpc/webapp/client.gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ExampleService {
constructor(hostname, fetch) {
this.path = '/rpc/ExampleService/'
this.hostname = hostname
this.fetch = fetch
this.fetch = () => fetch
}

url(name) {
Expand Down
110 changes: 63 additions & 47 deletions _examples/hello-webrpc/webapp/index.html
Original file line number Diff line number Diff line change
@@ -1,56 +1,72 @@
<!doctype html>
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<title>hello webrpc (js)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="" />
<script charset="utf-8" src="./client.gen.js" type="text/javascript"></script>
<style>
</style>
</head>
<body>

<div id="app">
<h1>hello webrpc, simple JS app -- open your console</h1>
</div>
<head>
<meta charset="utf-8" />
<title>hello webrpc (js)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="" />
<script
charset="utf-8"
src="./client.gen.js"
type="text/javascript"
></script>
<style></style>
</head>
<body>
<div id="app">
<h1>hello webrpc, simple JS app -- open your console</h1>
</div>

<script>
const svcFetch = window.fetch.bind(window)
let svc = new ExampleService('http://127.0.0.1:4242', svcFetch)
<script>
let svc = new ExampleService("http://127.0.0.1:4242", fetch);

// Expecting "true"
console.log('[A] webrpc -- calling Ping() rpc method (expecting true):')
// Expecting "true"
console.log("[A] webrpc -- calling Ping() rpc method (expecting true):");

svc.ping().then(resp => {
console.log('[A]', {resp})
}).catch(err => {
console.log('[A]', {err})
})
svc
.ping()
.then((resp) => {
console.log("[A]", { resp });
})
.catch((err) => {
console.log("[A]", { err });
});

// Expecting an error
console.log('[B] webrpc -- calling GetUser() rpc method of an unknown user (expecting a 404):')
// Expecting an error
console.log(
"[B] webrpc -- calling GetUser() rpc method of an unknown user (expecting a 404):"
);

svc.getUser({userID: 911}).then(resp => {
console.log('[B]', resp.user)
}).catch(err => {
console.log('[B]', {err})
})
svc
.getUser({ userID: 911 })
.then((resp) => {
console.log("[B]", resp.user);
})
.catch((err) => {
console.log("[B]", { err });
});

// Expecting some user data
console.log('[C] webrpc -- calling GetUser() rpc method (expecting User object):')
// Expecting some user data
console.log(
"[C] webrpc -- calling GetUser() rpc method (expecting User object):"
);

// svc.GetUser({userID: 966}).then(({ user }) => {
svc.getUser({userID: 966}).then(resp => {
const user = resp.user
console.log('[C]', {user})
console.log('[C] welcome user ID', user.id, 'with username', user.USERNAME)
}).catch(err => {
console.log('[C]', {err})
})


</script>

</body>
// svc.GetUser({userID: 966}).then(({ user }) => {
svc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the future, please do not merge formatting changes at the same time as other PRs. This is bad practice. and I also do not like the formatting here. I'd prefer if you could reverse.

.getUser({ userID: 966 })
.then((resp) => {
const user = resp.user;
console.log("[C]", { user });
console.log(
"[C] welcome user ID",
user.id,
"with username",
user.USERNAME
);
})
.catch((err) => {
console.log("[C]", { err });
});
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion client.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
constructor(hostname, fetch) {
this.path = '/rpc/{{.Name}}/'
this.hostname = hostname
this.fetch = fetch
this.fetch = () => fetch
}

url(name) {
Expand Down