本文整理匯總了TypeScript中mithril.request函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript request函數的具體用法?TypeScript request怎麽用?TypeScript request使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了request函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: updateTags
export function updateTags(deviceId, tags): Promise<void> {
return m.request({
method: "POST",
url: `/api/devices/${encodeURIComponent(deviceId)}/tags`,
data: tags
});
}
示例2: makeRequest
private static makeRequest(url: string,
method: string,
apiVersion?: ApiVersion,
options?: Partial<RequestOptions>): Promise<ApiResult<string>> {
const headers = this.buildHeaders(method, apiVersion, options);
let payload: any;
if (options && options.payload) {
payload = options.payload;
}
return m.request<XMLHttpRequest>({
url,
method,
headers,
data: payload,
extract: _.identity,
deserialize: _.identity,
config: (xhr) => {
if (options && options.xhrHandle) {
options.xhrHandle(xhr);
}
}
}).then((xhr: XMLHttpRequest) => {
return ApiResult.from(xhr);
}).catch((reason) => {
const unknownError = "There was an unknown error performing the operation.";
try {
return ApiResult.error(reason.responseText, JSON.parse(reason.message).message || unknownError, reason.status);
} catch {
return ApiResult.error(reason.responseText, unknownError, reason.status);
}
});
}
示例3: return
return (dispatch, getState) => {
dispatch(requestCode(uri));
request(uri, { deserialize: x => x })
.then(code => {
dispatch(recieveCode(uri, code));
});
}
示例4: queryConfig
export function queryConfig(pattern = "%"): Promise<any[]> {
const filter = stringify(["LIKE", ["PARAM", "_id"], pattern]);
return m.request({
method: "GET",
url: `api/config/?${m.buildQueryString({ filter: filter })}`,
background: true
});
}
示例5: logIn
export function logIn(username, password): Promise<void> {
return m.request({
method: "POST",
url: "/login",
background: true,
data: { username, password }
});
}
示例6: putResource
export function putResource(resourceType, id, object): Promise<void> {
for (const k in object) if (object[k] === undefined) object[k] = null;
return m.request({
method: "PUT",
url: `/api/${resourceType}/${encodeURIComponent(id)}`,
data: object
});
}
示例7: requestMesssge
public requestMesssge() {
return m.request({
method: "GET",
url: "/api/message",
initialValue: null
})
.then((data) => {
return new SampleMessage(data.value);
});
}
示例8: changePassword
export function changePassword(
username,
newPassword,
authPassword?
): Promise<void> {
const data = { newPassword };
if (authPassword) data["authPassword"] = authPassword;
return m.request({
method: "PUT",
url: `/api/users/${username}/password`,
background: true,
data
});
}
示例9: resourceExists
export function resourceExists(resource, id): Promise<number> {
const param = resource === "devices" ? "DeviceID.ID" : "_id";
const filter = ["=", ["PARAM", param], id];
return m.request({
method: "HEAD",
url:
`/api/${resource}/?` +
m.buildQueryString({
filter: memoizedStringify(filter)
}),
extract: xhr => +xhr.getResponseHeader("x-total-count"),
background: true
});
}
示例10: FormData
const upload = (e: Event) => {
const file = ((e.target as HTMLInputElement).files as FileList)[0];
const data = new FormData();
data.append("myfile", file);
m.request({
method: "POST",
url: "/api/v1/upload",
data,
config: xhr => {
xhr.addEventListener("progress", e => {
progress = e.loaded / e.total;
m.redraw(); // tell Mithril that data changed and a re-render is needed
});
}
});
};