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


TypeScript Http.method方法代碼示例

本文整理匯總了TypeScript中@angular/http.Http.method方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Http.method方法的具體用法?TypeScript Http.method怎麽用?TypeScript Http.method使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@angular/http.Http的用法示例。


在下文中一共展示了Http.method方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: makeRequest

  makeRequest(method: string, uri: string, params: Object, body:Object = null) {

    // build query string
    let queryParams = new URLSearchParams();
    // build query
    params = this.generateRequestQuery(uri, method, params, body);
    // url-ify
    Object.keys(params).forEach(k => {
      this.log(k, {});
      if (params[k] !== undefined) {
        queryParams.set(k, (typeof params[k] !== 'string' ? JSON.stringify(params[k]) : params[k]).replace(/\{/g, '%7B').replace(/\}/g, '%7D'));
      }
    });

    // Create request options
    let options:RequestOptions = this.generateRequestOptions(uri, method, params, body);

    // Add query string
    options.search = queryParams;

    this.log('Performing request with the following options', options);

    // Switch api based on method
    switch(method) {
      case 'get':
      case 'delete':
        return this.http[method](uri, options);
      default:
        return this.http[method](uri, JSON.stringify(body), options);
    }
  }
開發者ID:raghunat,項目名稱:ng2-data,代碼行數:31,代碼來源:store.service.ts

示例2: request

  private request(method: string, path: string, payload?) {
    let body = null;
    let headers = null
    let options = null;

    if (payload) {
      body = JSON.stringify(payload);
      headers = new Headers({ 'Content-Type': 'application/json' });
      options = new RequestOptions({ headers: headers });
    }

    return this.http[method](path, body, options).map((res) => res.json()).catch(this.handleError);
  }
開發者ID:ssimono,項目名稱:laika,代碼行數:13,代碼來源:backend.service.ts

示例3: request

  request(method, url, data = null) {
    let token = JwtToken.get();
    let options:RequestOptionsArgs = {
      "headers": new Headers({
        Accept: 'application/json',
        'Content-Type': 'application/json',
        Authorization: token
      })
    };
    let finalUrl = `${Config.API_URL}${url}`;
    let query;
    switch (method) {
      case 'get':
        options.search = this._mapToURLSearchParams(data);
        query = this.http.get(finalUrl, options);
        break;
      case 'delete':
        query = this.http.delete(finalUrl, options);
        break;
      default:
        query = this.http[method](finalUrl, JSON.stringify(data), options);
        break;
    }

    return query.catch((response) => {
      //error handling
      //noinspection TypeScriptUnresolvedFunction
      let text = response.text();
      let error = null;
      try {
        error = JSON.parse(text);
        error = error.error;
      }
      finally {
      }
      if (error) {
        throw error;
      } else {
        throw response;
      }
    }).map(result => {
        let text = result.text();
        //e.g. empty result can be returned for "delete"
        if (text === '') {
          return {};
        }
        //noinspection TypeScriptUnresolvedFunction
        return result.json()
      })
      .map(ApiService.proceedDates)
  }
開發者ID:flaper,項目名稱:angular,代碼行數:51,代碼來源:ApiService.ts

示例4: addDepartament

  addDepartament(dep:Departament, _method:any): Promise<Departament[]> {

  	let headers = new Headers({
    'Content-Type': 'application/json'});
    let method = 'post';

    if(_method == "modify"){
    	method = 'put';
    }

    return this.http[method]('http://0.0.0.0:3000/api/Departments',JSON.stringify(dep), {headers: headers})
               .toPromise()
               .then(response => 
               		response.json())
               .catch(this.handleError);
  }
開發者ID:shabetya,項目名稱:angular2-sample,代碼行數:16,代碼來源:departments.service.ts

示例5: save

  save(app: Appointment): Observable<Appointment> {
    let body = JSON.stringify(app);
    let token = sessionStorage.getItem('token');
    let headers = new Headers();
    headers.append('Authorization', 'Bearer ' + token);

    let url = 'http://api.marabinigomme.it/appointments';
    let method = 'put';

    if (app.id) {
      url = url + '/' + app.id;
      method = 'post';
    }

    return this.http[method](url, body, new RequestOptions({headers: headers}))
      .map(this.extractData)
      .catch(this.handleError);
  }
開發者ID:codeclysm,項目名稱:mara,代碼行數:18,代碼來源:calendar.service.ts

示例6: load_json

 private load_json(method, uri, params, resolve) {
   let resolved = false;
   this._http[method](uri, { search: params }).subscribe(
     res => {
       try {
         resolve(res.json());
         resolved = true;
       } catch (e) {
         console.error("Failed jsoning", res, resolved);
       }
     },
     error => setTimeout(() => {
       console.error("HTTP Error", error);
       this.load_json(method, uri, params, resolve);
     }, 1000),
     () => {
       if (!resolved) {
         console.error("Not resolved but completed");
         this.load_json(method, uri, params, resolve);
       }
     });
 }
開發者ID:felix-halim,項目名稱:uhunt,代碼行數:22,代碼來源:http.ts

示例7: makeRequest

 private makeRequest(method: string, requestBody?: string): Observable<any> {
   return this._http[method](Config.apiUrl + "Groceries",
     { headers: this.header }, requestBody)
     .map(res => res.json())
     .catch(this.handleErrors);
 }
開發者ID:abiodun0,項目名稱:Angular-2-Grocery-Store-Native-App,代碼行數:6,代碼來源:grocery-list.service.ts

示例8: load_text

 private load_text(method, uri, params, resolve) {
   this._http[method](uri, { search: params })
     .subscribe(res => resolve(res), error => setTimeout(() =>
       this.load_text(method, uri, params, resolve), 1000));
 }
開發者ID:felix-halim,項目名稱:uhunt,代碼行數:5,代碼來源:http.ts

示例9: rawRequest

 rawRequest(method: string, route: string, params: Object, body:Object) {
   return this.http[method](`${StoreService.config.baseUri}/${route}`, params, body);
 }
開發者ID:raghunat,項目名稱:ng2-data,代碼行數:3,代碼來源:store.service.ts

示例10: requestVoid

 private requestVoid(url: string, data: {}, method: string = 'post'): Observable<void> {
   return this.http[method](url, data).map(response => {}).catch(this.handleError);
 }
開發者ID:coompany,項目名稱:coompany-site,代碼行數:3,代碼來源:backend.service.ts


注:本文中的@angular/http.Http.method方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。