本文整理匯總了TypeScript中@servicestack/client.JsonServiceClient類的典型用法代碼示例。如果您正苦於以下問題:TypeScript JsonServiceClient類的具體用法?TypeScript JsonServiceClient怎麽用?TypeScript JsonServiceClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了JsonServiceClient類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: createUrl
HelloTypes,
ReturnString, ReturnBytes, ReturnStream,
TestAuth, TestAuthResponse,
HelloReturnVoid,
EchoTypes
} from "./Test.dtos";
function createUrl(path: string, params: any): string {
for (var key in params) {
path += path.indexOf('?') <= 0 ? "?" : "&";
path += key + "=" + encodeURIComponent(params[key]);
}
return path;
}
var client = new JsonServiceClient("/");
$(document).bindHandlers({
sayHello () {
var request = new Hello();
request.name = this.value;
$.getJSON(createUrl("/hello", request), function (r: HelloResponse) {
$("#helloResult").html(r.result);
});
},
sayHelloRoute () {
var request = new Hello();
request.name = this.value;
request.title = "Dr";
$.getJSON($.ss.createUrl("/hello/{Name}", request), request, function (r: HelloResponse) {
$("#helloRouteResult").html(r.result);
示例2: function
deleteContact: async function(id:number) {
if (!confirm('Are you sure?'))
return;
await client.delete(new DeleteContact({ id }));
const response = await client.get(new GetContacts());
CONTACTS = response.results;
render();
}
示例3: evalExpression
export function evalExpression(gist: string, scriptId: string, expr: string) {
if (!expr)
return;
const request = new EvaluateExpression();
request.scriptId = scriptId;
request.expression = expr;
request.includeJson = true;
ReactGA.event({ category: 'preview', action: 'Evaluate Expression', label: gist + ": " + expr.substring(0, 50) });
client.post(request)
.then(r => {
if (r.result.errors && r.result.errors.length > 0) {
r.result.errors.forEach(x => {
store.dispatch({ type: 'CONSOLE_LOG', logs: [{ msg: x.info, cls: "error" }] });
});
} else {
store.dispatch({ type: 'EXPRESSION_LOAD', expressionResult: r.result });
}
})
.catch(e => {
var status = e.responseStatus || e; //both have schema `{ message }`
store.dispatch({ type: 'CONSOLE_LOG', logs: [statusToError(status)] });
});
};
示例4: testClient
function testClient() {
client.get(Object.assign(new Hello(), { name: "GET" })).then(show);
client.post(Object.assign(new Hello(), { name: "POST" })).then(show);
client.put(Object.assign(new Hello(), { name: "PUT" })).then(show);
};