first-api & file-upload
This commit is contained in:
26
examples/first-api/frontend/src/index.ts
Normal file
26
examples/first-api/frontend/src/index.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { HttpClient } from 'tsrpc-browser';
|
||||
import { serviceProto } from './shared/protocols/serviceProto';
|
||||
|
||||
// Create the Client
|
||||
let client = new HttpClient(serviceProto, {
|
||||
server: 'http://127.0.0.1:3000',
|
||||
logger: console
|
||||
});
|
||||
|
||||
async function test() {
|
||||
// callApi
|
||||
let ret = await client.callApi('Hello', {
|
||||
name: 'World'
|
||||
});
|
||||
|
||||
// Error
|
||||
if (!ret.isSucc) {
|
||||
alert('Error: ' + ret.err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
// Success
|
||||
alert('Success: ' + ret.res.reply);
|
||||
}
|
||||
|
||||
window.onload = test;
|
@@ -0,0 +1,8 @@
|
||||
export interface ReqHello {
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface ResHello {
|
||||
reply: string,
|
||||
time: Date
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
import { ServiceProto } from 'tsrpc-proto';
|
||||
import { ReqHello, ResHello } from './PtlHello';
|
||||
|
||||
export interface ServiceType {
|
||||
api: {
|
||||
"Hello": {
|
||||
req: ReqHello,
|
||||
res: ResHello
|
||||
}
|
||||
},
|
||||
msg: {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export const serviceProto: ServiceProto<ServiceType> = {
|
||||
"services": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "Hello",
|
||||
"type": "api"
|
||||
}
|
||||
],
|
||||
"types": {
|
||||
"PtlHello/ReqHello": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "name",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlHello/ResHello": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "reply",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "time",
|
||||
"type": {
|
||||
"type": "Date"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user