當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript isomorphic-fetch類代碼示例

本文整理匯總了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;未經允許,請勿轉載。