本文整理汇总了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
});
}
});
};