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


TypeScript aurelia-fetch-client.HttpClient類代碼示例

本文整理匯總了TypeScript中aurelia-fetch-client.HttpClient的典型用法代碼示例。如果您正苦於以下問題:TypeScript HttpClient類的具體用法?TypeScript HttpClient怎麽用?TypeScript HttpClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: constructor

	constructor(private http: HttpClient, private observerLocator: ObserverLocator) {
		//localStorage.clear();
		this.contacts = JSON.parse(localStorage.getItem(Constants.STORAGE_CONTACTS));

		if (!this.contacts) {
			http.configure(config => {
				config.useStandardConfiguration().withBaseUrl('https://api.github.com/');
			});
			http.fetch('users')
				.then(response => response.json())
				.then(users => {
					this.contacts = users.map((user: { id: number, login: string, avatar_url: string, type: string }) => {
						let contact = new Contact();
						contact.id = user.id;
						contact.username = user.login;
						contact.email = user.login + "@email.com";
						contact.avatarUrl = user.avatar_url;
						contact.description = user.type;
						contact.checked = false;

						return contact;
					});
					this.contacts = this.contacts.splice(20);

					this.updateStorage();
					this.applyObservers();
				});
		}
	}
開發者ID:ishyfishyy,項目名稱:aurelia-contacts,代碼行數:29,代碼來源:store.ts

示例2: beforeEach

 beforeEach(()=> {
     http = new HttpClient();
     http = http.configure(config => {
         config
             .useStandardConfiguration()
             .withBaseUrl(teamcity)
             .withDefaults({
                 headers: {
                     'Accept': 'application/json'
                 }
             });
     });
 });
開發者ID:sasha-uk,項目名稱:xradiate,代碼行數:13,代碼來源:api.spec.ts

示例3: constructor

 constructor(private http: HttpClient) {
   http.configure(config => {
     config
       .useStandardConfiguration()
       .withBaseUrl('https://api.github.com/');
   });
 }
開發者ID:ltrain777,項目名稱:skeleton-navigation,代碼行數:7,代碼來源:githubservice.ts

示例4: constructor

  constructor(public httpClient: HttpClient,
    public appState: UIApplication,
    public eventAggregator: EventAggregator) {
    this.appState.info(this.constructor.name, 'Initialized');

    let self = this;
    httpClient.configure(
      config => {
        config
          .withBaseUrl(UIConstants.Http.BaseUrl)
          //.withDefaults({})
          .withInterceptor({
            request(request) {
              appState.info(self.constructor.name, `Requesting ${request.method} ${request.url}`);
              appState.IsHttpInUse = true;
              //request.url = encodeURI(request.url);
              return request;
            },
            response(response) {
              appState.info(self.constructor.name, `Response ${response.status} ${response.url}`);
              appState.IsHttpInUse = false;

              if (response instanceof TypeError) {
                throw Error(response['message']);
              }

              if (response.status == 401) {
                eventAggregator.publish('Unauthorized', null);
              }
              else if (response.status != 200) {
                return response.text()
                  .then(resp => {
                    let json: any = {};
                    let error = 'Network Error!!';
                    try {
                      console.log(resp);
                      json = JSON.parse(resp);
                      if (json.message) error = json.message;
                      else if (json.error) error = json.error;
                      else if (response.statusText) error = response.statusText;
                    } catch (e) { }
                    if (error) throw new Error(error);
                    return null;
                  });
              }
              return response;
            },
            requestError(error) {
              appState.IsHttpInUse = false;
              if (error !== null) throw Error(error.message);
              return error;
            },
            responseError(error) {
              appState.IsHttpInUse = false;
              if (error !== null) throw Error(error.message);
              return error;
            }
          });
      });
  }
開發者ID:sigmaframeworks,項目名稱:sigma-ui-framework,代碼行數:60,代碼來源:ui-http-service.ts

示例5: constructor

 constructor(private _http: HttpClient, private _eventAggregator: EventAggregator) {
     _http.configure(config => {
         config
             .useStandardConfiguration()
             .withBaseUrl('http://localhost:8080/api/');
     });
 };
開發者ID:JDTLH9,項目名稱:aurelia-kaizen,代碼行數:7,代碼來源:todo-store.ts

示例6: students

  static get students() {
     return {
         getAll() {
             return httpClient.fetch('students/getAll');
         },
         register(user) {
             return httpClient.fetch('oauth/register',
             {
                 method: 'post',
                 body: json(user)
             });
         }
     }
 }
開發者ID:Lesslimit,項目名稱:MeeToo,代碼行數:14,代碼來源:dataService.ts

示例7: save

 save(customer: Customer): Promise<Customer> {
   if (customer.id) {
     return this.http.fetch(`${baseUrl}/${customer.id}`, {
       method: 'put',
       body: json(customer)
     })
     .then(response => response.json());
   }
   else {
     return this.http.fetch(`${baseUrl}`, {
       method: 'post',
       body: json(customer)
     })
     .then(response => response.json());
   }
 }
開發者ID:ghiscoding,項目名稱:Realtime-TODO-Aurelia-RethinkDB,代碼行數:16,代碼來源:customerData.ts

示例8: create

 create(entity:Pessoa){
     return this.httpClient.fetch('pessoas',{
         method: 'post',
         redirect: 'follow',
         body: json(entity)
     });
 }
開發者ID:Diego-Rocha,項目名稱:stack-sample,代碼行數:7,代碼來源:pessoa-service.ts

示例9: getPosts

 getPosts(): Promise<IPost[]>{
   return this._http.fetch('../../../../data/posts.json').then(response => {
     return response.text();
   }).then(data => {
     return JSON.parse(data);
   });
 }
開發者ID:avizcaino,項目名稱:avizcaino.github.io,代碼行數:7,代碼來源:blog-service.ts

示例10: archiveAllCompleted

 archiveAllCompleted(): Promise<Todo[]> {
   return this.http.fetch(`${baseUrl}/archive-all-completed`, {
     method: 'post',
     body: null
   })
   .then(response => response.json());
 }
開發者ID:ghiscoding,項目名稱:Realtime-TODO-Aurelia-RethinkDB,代碼行數:7,代碼來源:todoData.ts


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