Example #1
0
 private fetchTodos(){
     let request = this.http.request("/api/TodoItems");
     
     request.subscribe((response: Response) => {
         this.todos = response.json().map(todo => new TodoItem(todo.Value, todo.Done, todo.ID))
     }, (error) => alert("Error: " + JSON.stringify(error)));
 }
 public executeRequest(pObserver, pOpt: RequestOptions) {
     console.log('Start request to ' + pOpt.url);
     let vCurrentContext = this;
     vCurrentContext._modalService.showErrorModal('Start request to ' + pOpt.url);
     this._http.request(new Request(pOpt))
         .timeout(this.vTimeout, {status: 408})
         .subscribe(
             (res) => {
                 pObserver.next(res);
                 pObserver.complete();
             },
             (err) => {
                 switch (err.status) {
                     case 403:
                         // caused by invalid token sent to server
                         // try access once again using refresh token
                         // if still failed redirect to login page
                         pObserver.error(err);
                         break;
                     case 400: // system error
                         pObserver.error(err.json());
                         break;
                     case 500: // functional error
                         pObserver.error(err);
                     default:
                         // throw error
                         pObserver.error(err);
                         break;
                 }
             });
 }
  private request(requestArgs: RequestOptionsArgs, additionalArgs?: RequestOptionsArgs) {
    let opts = new RequestOptions(requestArgs);

    if (additionalArgs) {
      opts = opts.merge(additionalArgs);
    }

    let req:Request = new Request(opts);

    if (!req.headers) {
      req.headers = new Headers();
    }

    if (!req.headers.has('Authorization')) {
      req.headers.append('Authorization', `Bearer ${this.getToken()}`);
    }

    return this._http.request(req).catch((err: any) => {
      if (err.status === 401) {
        this.unauthorized.next(err);
      }

      return Observable.throw(err);
    });
  }
Example #4
0
    constructor(private http: Http) {

        let opts = new RequestOptions({ method: 'GET' });

        this.http.request('http://127.0.0.1:4001/api/ping', opts)
            .map(x => x.json())
            .subscribe(res => this.apiPing = res.ping);
    }
Example #5
0
 //http://jsonplaceholder.typicode.com/
 // makeRequest():void {
 //     this.loading = true;
 //     this.http.request('http://jsonplaceholder.typicode.com/users')
 //         .subscribe((res:Response) => {
 //             this.data = res.json();
 //             this.loading = false;
 //         });
 // }
 ngOnInit():any {
     this.loading = true;
     this.http.request('http://localhost:3000/data/test-users.json')
         .subscribe((res:Response) => {
             this.data = res.json();
             this.loading = false;
         });
 }
 all(url:string) {
     var options = new RequestOptions({
         method: RequestMethod.Get,
         url: url
     });
     var req = new Request(options);
     return this.http.request(req);
 }
 makeRequest(): void {
   this.loading = true;
   this.http.request('http://jsonplaceholder.typicode.com/posts/1')
     .subscribe((res: Response) => {
       this.data = res.json();
       this.loading = false;
     });
 }
Example #8
0
    signup(user, opts?: RequestOptionsArgs): Observable<Response> {
        opts = opts || {};
        let url = opts.url ? opts.url : joinUrl(this.config.baseUrl, this.config.signupUrl);
        opts.body = JSON.stringify(user) || opts.body;
        opts.method = opts.method || 'POST';

        return this.http.request(url, opts);
    }
Example #9
0
 unlink(provider: string, opts: RequestOptionsArgs) {
     opts = opts || {};
     let url = opts.url ? opts.url : joinUrl(this.config.baseUrl, this.config.unlinkUrl);
     opts.body = JSON.stringify({ provider: provider }) || opts.body;
     opts.method = opts.method || 'POST';
     
     return this.http.request(url, opts);
 }
    deleteIssue(id) {
        let firstHeaders = new Headers();
        firstHeaders.append('Content-Type', 'text/plain;charset=UTF-8');

        return this.http.request(new Request({
            method: APIS.HTTP_METHODS.GET,
            url: APIS.DELETE_ISSUE + id
        })).map(res => res.json());
    }
    listIssues() {
        let firstHeaders = new Headers();
        firstHeaders.append('Content-Type', 'text/plain;charset=UTF-8');

        return this.http.request(new Request({
            method: APIS.HTTP_METHODS.GET,
            url: APIS.LIST_ISSUES + APIS.USER
        })).map(res => res.json());
    }
  getContactById(id: number): Observable<Contact> {
    var req = this.generateRequest('/\contacts/' + id, 'Get');

    return this._http.request(req).map(
      (resp: Response) => {
        return resp.json().item;
      }
    );
  }
 all(_url:string, _search?:Object) {
     var options = new RequestOptions({
         method: RequestMethod.Get,
         url: _url,
         search: Util.getInstance().URLParams().parse(_search)
     });
     var req = new Request(options);
     return this.http.request(req);
 }
 getRequest(_url:string, _search?:Object, _header?:Object) {
     var options = new RequestOptions({
         method: RequestMethod.Get,
         headers: Util.getInstance().requestHeader().setHeaderParams(_header),
         url: _url,
         search: Util.getInstance().urlParams().parse(_search)
     });
     var req = new Request(options);
     return this.http.request(req);
 }
 return new Promise((resolve, reject) => {
     this.http
         .request(requestUrl, {
             method: "get"
         }).map<any>(response => {
             return response.json();
         }).subscribe(
         data => resolve(data),
         error => reject(error)
         );
 });
Example #16
0
	addRecipe(recipe: Recipe) {
		var headers = new Headers();
		headers.append('Content-Type', 'application/json');
		var options = new RequestOptions({
			method: RequestMethod.Post,
			headers: headers,
			url: '/api/recipes/',
			body: JSON.stringify(recipe)
		});
		return this._http.request(new Request(options));
	}
    updateIssue(params:any) {

        let firstHeaders = new Headers();
        firstHeaders.append('Content-Type', 'text/plain;charset=UTF-8');

        return this.http.request(new Request({
            method: APIS.HTTP_METHODS.POST,
            url: APIS.UPDATE_ISSUE,
            search: this.commonService.serializeObj(params)
        })).map(res => res.json());
    }
  getContacts(): Observable<Contact[]> {

    var req = this.generateRequest('/\contacts', 'Get');

    return this._http.request(req).map(
      (resp: Response) => {
        return resp.json().items;
      }
    );

  }
Example #19
0
    return this.token$.flatMap(token => {
      options.headers = new Headers();
      options.headers.append('Content-Type', 'Bearer ' + 'application/json');
      options.headers.append('Authorization', 'Bearer ' + token);

      if (options.body && typeof options.body !== 'string') {
        options.body = JSON.stringify(options.body);
      }

      return this.http.request(new Request(options)).map((res: Response) => res.json());
    });
Example #20
0
 updateFamily(family) {
     var headers = new Headers();
     headers.append('Content-Type', 'application/json');
     var options = new RequestOptions({
         method: RequestMethod.Put,
         headers: headers,
         url: '/api/products/family/' + family._id,
         body: JSON.stringify(family)
     });
     return this._http.request(new Request(options));
 }
Example #21
0
 addCategory(category: Category) {
     var headers = new Headers();
     headers.append('Content-Type', 'application/json');
     var options = new RequestOptions({
         method: RequestMethod.Post,
         headers: headers,
         url: '/api/products/category/',
         body: JSON.stringify(category)
     });
     return this._http.request(new Request(options));
 }
 public addUsers(user: Immutable.Stack<Models.UserModel>): ServiceBase.IPromise {
     
     return this.http
         .request(`api/typewriterTest/`, {
             method: "post",
             body: ServiceBase.stringifyBody(user)
         })
         .map(response => {
             return null;
         })
         .toPromise();
 }
Example #23
0
 public update(issueModel: Models.IssueModel): ServiceBase.IPromise {
     
     return this.http
         .request(`api/issue/Update`, {
             method: "put",
             body: ServiceBase.stringifyBody(issueModel)
         })
         .map(response => {
             return null;
         })
         .toPromise();
 }
    authenticate(params) {

        let loginHeaders = new Headers();
        loginHeaders.append('Content-Type', 'text/plain;charset=UTF-8');

        return this.http.request(new Request({
            method: APIS.HTTP_METHODS.GET,
            headers: loginHeaders,
            url: APIS.AUTH_USER,
            search: this.commonService.serializeObj(params)
        })).map(res => res.json());
    }
	private request(path: string, method: RequestMethod, body?: Object, search?: Object): Observable<any> {
		let options = new RequestOptions(this.restOptions.merge({
			method: method,
			url: this.restOptions.url + path,
			body: JSON.stringify(body),
			search: this.serialize(search)
		}));

		return this.http
			.request(new Request(options))
			.map((res: Response) => res.json());
	}
 public deleteUser(userId: string): ServiceBase.IPromise {
     
     return this.http
         .request(`api/typewriter/DeleteUser`, {
             method: "delete",
             body: ServiceBase.stringifyBody(userId)
         })
         .map(response => {
             return null;
         })
         .toPromise();
 }
 public getSimpleStringMessageFromCustomRoute(message: string): ServiceBase.ITypedPromise<string> {
     
     return this.http
         .request(`api/typewriter/api/messages/getMessage/${message}`, {
             method: "get",
             body: ServiceBase.stringifyBody(null)
         })
         .map<string>(response => {
             return response.json();
         })
         .toPromise();
 }
 public getCreationDate(): ServiceBase.ITypedPromise<Headers> {
     
     return this.http
         .request(`api/typewriter/GetCreationDate`, {
             method: "head",
             body: ServiceBase.stringifyBody(null)
         })
         .map<Headers>(response => {
             return response.headers;
         })
         .toPromise();
 }
 public modifyUserWithoutResult(user: Models.UserModel): ServiceBase.IPromise {
     
     return this.http
         .request(`api/typewriter/ModifyUserWithoutResult`, {
             method: "post",
             body: ServiceBase.stringifyBody(user)
         })
         .map(response => {
             return null;
         })
         .toPromise();
 }
 public getSimpleStringMessage(): ServiceBase.ITypedPromise<string> {
     
     return this.http
         .request(`api/typewriter/GetSimpleStringMessage`, {
             method: "get",
             body: ServiceBase.stringifyBody(null)
         })
         .map<string>(response => {
             return response.json();
         })
         .toPromise();
 }