当前位置: 首页>>代码示例>>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;未经允许,请勿转载。