custom http res
This commit is contained in:
26
examples/custom-http-res/src/api/ApiAddData.ts
Normal file
26
examples/custom-http-res/src/api/ApiAddData.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { ApiCall } from "tsrpc";
|
||||
import { ReqAddData, ResAddData } from "../shared/protocols/PtlAddData";
|
||||
import { AllData } from "./ApiGetData";
|
||||
|
||||
// This is a demo code file
|
||||
// Feel free to delete it
|
||||
|
||||
export async function ApiAddData(call: ApiCall<ReqAddData, ResAddData>) {
|
||||
// Error
|
||||
if (call.req.content === '') {
|
||||
call.error('Content is empty');
|
||||
return;
|
||||
}
|
||||
|
||||
let time = new Date();
|
||||
AllData.unshift({
|
||||
content: call.req.content,
|
||||
time: time
|
||||
})
|
||||
console.log('AllData', AllData)
|
||||
|
||||
// Success
|
||||
call.succ({
|
||||
time: time
|
||||
});
|
||||
}
|
13
examples/custom-http-res/src/api/ApiGetData.ts
Normal file
13
examples/custom-http-res/src/api/ApiGetData.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { ApiCall } from "tsrpc";
|
||||
import { ReqGetData, ResGetData } from "../shared/protocols/PtlGetData";
|
||||
|
||||
// This is a demo code file
|
||||
// Feel free to delete it
|
||||
|
||||
export async function ApiGetData(call: ApiCall<ReqGetData, ResGetData>) {
|
||||
call.succ({
|
||||
data: AllData
|
||||
})
|
||||
}
|
||||
|
||||
export const AllData: { content: string, time: Date }[] = [];
|
Reference in New Issue
Block a user