github.com/vcilabs/webrpc@v0.5.2-0.20201116131534-162e27b1b33b/gen/javascript/templates/client.js.tmpl (about) 1 {{define "client"}} 2 {{- if .Services}} 3 // 4 // Client 5 // 6 {{ range .Services}} 7 {{exportKeyword}}class {{.Name}} { 8 constructor(hostname, fetch) { 9 this.path = '/rpc/{{.Name}}/' 10 this.hostname = hostname 11 this.fetch = fetch 12 } 13 14 url(name) { 15 return this.hostname + this.path + name 16 } 17 {{range .Methods}} 18 {{.Name | methodName}} = ({{.Inputs | methodInputs}}) => { 19 return this.fetch( 20 this.url('{{.Name}}'), 21 {{- if .Inputs | len}} 22 createHTTPRequest(args, headers) 23 {{- else}} 24 createHTTPRequest({}, headers) 25 {{- end}} 26 ).then((res) => { 27 return buildResponse(res).then(_data => { 28 return { 29 {{- $outputsCount := .Outputs|len -}} 30 {{- range $i, $output := .Outputs}} 31 {{$output | newOutputArgResponse}}{{listComma $i $outputsCount}} 32 {{- end}} 33 } 34 }) 35 }) 36 } 37 {{end}} 38 } 39 {{end -}} 40 {{end -}} 41 {{end}}