本文整理汇总了TypeScript中isomorphic-fetch类的典型用法代码示例。如果您正苦于以下问题:TypeScript isomorphic-fetch类的具体用法?TypeScript isomorphic-fetch怎么用?TypeScript isomorphic-fetch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了isomorphic-fetch类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: test_whatwgTestCases_es6
function test_whatwgTestCases_es6() {
var headers = new Headers();
headers.append("Content-Type", "application/json");
var requestOptions: RequestInit = {
method: "POST",
headers: headers,
mode: 'same-origin',
credentials: 'omit',
cache: 'default'
};
expectSuccess(fetchImportedViaES6Module('http://localhost:3000/poster', requestOptions), 'Post response:');
var requestOptions: RequestInit = {
method: "POST",
headers: {
'Content-Type': 'application/json'
}
};
expectSuccess(fetchImportedViaES6Module('http://localhost:3000/poster', requestOptions), 'Post response:');
var requestOptions: RequestInit = {
method: "POST",
headers: {
'Content-Type': 'application/json'
}
};
var request: Request = new Request('http://localhost:3000/poster', requestOptions);
expectSuccess(fetchImportedViaES6Module(request), 'Post response:');
}
开发者ID:1drop,项目名称:DefinitelyTyped,代码行数:32,代码来源:isomorphic-fetch-tests.ts
示例2: test_isomorphicFetchTestCases_es6
function test_isomorphicFetchTestCases_es6() {
expectSuccess(fetchImportedViaES6Module('http://localhost:3000/good'), 'Good response');
fetchImportedViaES6Module('http://localhost:3000/bad')
.then((response: IResponse) => {
return response.text();
})
.catch((err) => {
});
}
开发者ID:1drop,项目名称:DefinitelyTyped,代码行数:10,代码来源:isomorphic-fetch-tests.ts
示例3: return
return (dispatch: Dispatch<any>) => {
fetch('//localhost:1337/user/'+ user.id +'/services', {
method: 'POST',
credentials: 'include',
body: JSON.stringify({
title: title,
description: description,
price: price
})
})
.then(function(response: any) {
if (response.status >= 400) {
dispatch(throwErrror(__('Bad response from server.')))
}
return response.json();
})
.then(function(response: any) {
if(response.services)
{
dispatch(addedService(response.services))
dispatch(push('/'))
}
})
.catch(function(err: any) {
dispatch(throwErrror(__('Error : cannot connect to the server.')))
})
}
开发者ID:nyamteam,项目名称:web-client,代码行数:27,代码来源:serviceAction.ts
示例4:
{ _:({postsBySubreddit,selectedSubreddit},payload,meta,actions,dispatch)=>
shouldFetchPosts(postsBySubreddit,selectedSubreddit) ?
fetch(`https://www.reddit.com/r/${selectedSubreddit}.json`)
.then(response => response.json())
.then(json=>json.data.children.map(child=>child.data))
.catch(err=>console.log(err)):
null
开发者ID:Xananax,项目名称:actionsreducer,代码行数:7,代码来源:data.ts
示例5: async
const uploadToServer = async (canvas: HTMLCanvasElement) => {
const data = canvas.toDataURL('image/jpeg', 0.6);
const encodedjpg = data.substring(data.indexOf(',') + 1, data.length);
const body = new FormData();
body.append('filename', 'result_');
body.append('image', encodedjpg);
const res = await fetch('http://thesecretfarm.com/cheerup/writeImage.php', {
method: 'POST',
body,
});
const resJson = await res.json();
const md = new MobileDetect(window.navigator.userAgent);
if (md.mobile()) {
const shareURL = `https://www.facebook.com/dialog/feed?app_id=${Setting.fbAppId}&link=${Setting.shareInfo.link}&name=${Setting.shareInfo.title}&caption=${Setting.shareInfo.caption}&description=${Setting.shareInfo.description}&picture=${'http://www.thesecretfarm.com/cheerup/result/' + resJson.filename + '.jpg'}&redirect_uri=${Setting.redirectURL}`;
window.location.href = shareURL;
} else {
const uiParams = {
method: 'feed',
name: Setting.shareInfo.title,
title: Setting.shareInfo.title,
link: Setting.shareInfo.link,
caption: Setting.shareInfo.caption,
description: Setting.shareInfo.description,
display: 'iframe',
picture: 'http://www.thesecretfarm.com/cheerup/result/' + resJson.filename + '.jpg', // 'http://www.thesecretfarm.com/creativegift/star_55652e81082027.jpg'//'http://gth.co.th/startheque/result/'+res.filename+'.jpg',//'http://www.thesecretfarm.com/creativegift/star_55652e81082027.jpg'//
} as any;
return new Promise<any>((fulfill, reject) => {
FB.ui(uiParams, function (response: any): void {
fulfill(response);
});
});
}
};
开发者ID:zapkub,项目名称:CheerUp-Thailand,代码行数:35,代码来源:share.actions.ts
示例6: Promise
return new Promise((resolve, reject) => {
console.log(url);
fetch(url)
.then(apiResult => apiResult.json())
.then(json => resolve(json)) // Success
.catch(error => reject(error)); // Fail
});
开发者ID:toannvbk93,项目名称:goemon,代码行数:7,代码来源:todo-list-service.ts
示例7: fetch
export function fetchData<T>(url: string, level?: FetchLevel): Promise<T> {
const fullURL = Constants.API_SERVER_BASE_URL + url;
if (level && appState.isClientEnv) {
appState.addFetch(url, level);
}
return fetch(fullURL,
{
headers: {
"Accept": "application/vnd.api+json"
}
})
.then(response => response.json())
.then((data) => {
if (level && appState.isClientEnv) {
appState.deleteFetch(url);
}
return new Deserializer({ keyForAttribute: "camelCase" }).deserialize(data);
})
.catch((err: Error) => {
console.error(err.message);
return err;
});
};
开发者ID:vandemataramlib,项目名称:vml-web,代码行数:29,代码来源:utils.ts
示例8: login
login(email?: string, password?: string): Promise<{ readonly token: string }> {
if (!this.host) throw new Error('Should set the host url')
const options = {
method: Method.POST,
headers: new Headers({
'Content-Type': 'application/json',
}),
body: JSON.stringify({
email: email || this.email,
password: password || this.password,
}),
}
const request = fetch(`${this.host}${Path.LOGIN}`, options)
return Promise.race([request, this.timeoutPromise()])
.then(async (value: any) => {
if (value.ok) return await value.json()
throw await value.text()
})
.catch(e => {
throw e
})
}
开发者ID:aconly,项目名称:frost-client,代码行数:26,代码来源:Frost.ts
示例9: return
return (dispatch: Dispatch<any>) => {
dispatch(loginRequest())
fetch('//localhost:1337/login', {
method: 'POST',
credentials: 'include',
body: JSON.stringify({
email: username,
password: password,
})
})
.then(function(response: any) {
if (response.status >= 400) {
dispatch(throwErrror(__('Bad response from server.')))
}
return response.json();
})
.then(function(response: any) {
if(response.user)
{
let user = response.user
dispatch(initCurrentUser(user))
dispatch(loggedInSuccess())
dispatch(push('/'))
} else {
dispatch(loggedInFailed(response.message))
}
})
.catch(function(err: any) {
dispatch(throwErrror(__('Error : cannot connect to the server.')))
})
}
开发者ID:nyamteam,项目名称:web-client,代码行数:31,代码来源:loginAction.ts
示例10: it
it("index.html returns null", (done: MochaDone) => {
let p2: Promise<ParsedTimestamp> =
fetch(serverUrl + "/index.html")
.then((res: IResponse) => res.json());
promiseAssert(p2, done, (j: ParsedTimestamp): void => {
chai.expect(j).to.deep.equal(nullTS);
});
});
开发者ID:jw120,项目名称:fcc-timestamp,代码行数:8,代码来源:server_spec.ts
注:本文中的isomorphic-fetch类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论