post(request) {
        //console.log(request)

        let body = JSON.stringify(request.data);
        
        let headers = this.buildHeaders([
            { key: 'Content-Type', value: 'application/json' },
            { key: 'Accept', value: 'application/json' }
        ]);

        let options = new RequestOptions({ headers: headers });

        return this.http.post(request.url, body, options);
    }
 addRole(role) {
     var headers = new Headers();
     headers.append('Content-Type', 'application/json');
     return this._http.post(this._config.apiEndpoint + '/role', JSON.stringify(role), { // All hosts to config.
         headers: new Headers({
             'Authorization': 'Bearer ' + this._auth.getToken(),
             'Content-Type': 'application/json'
         })
     }).map((res) => {
         let doc = res.json();
         let roles = doc;
         return roles;
     });
 }
Example #3
0
 .flatMap( (saga)=>{
     console.log('init post ',saga);
     var t=localStorage.getItem('token'); 
     if (t==null) return Observable.of(null);
     var h:Headers=new Headers();
     h.append('Authorization',t);
     
     const query=http.post('http://virtual2.ballistix.co.uk:8000/api/maintenance',JSON.stringify({type:''}),{headers:h});
 
       
 
     return query.map((e)=>e.json()).catch((e)=>{return Observable.of(null)});
    
 })
    // PUT
    public putAlumno(alumno: Alumno) {

        var obj = {
            '__metadata': { 'type': 'SP.Data.AlumnoListItem' },
            'Nombre': alumno.nombre,
            'Apellidos': alumno.apellidos,
            'Puntuacion': alumno.puntuacion,
            'Guid': alumno.userGuid,
            'AccountName': alumno.accountName
        };

        var data = JSON.stringify(obj);
        return this.http.post(this.spApiUrl + "/_api/web/lists/getByTitle('Alumno')/items(" + alumno.id + ")", data, { headers: this.setHeaders("PUT") });
    }
Example #5
0
 let result = Observable.create((observable) => {
   this._http.post(this.getSaveEndpoint(obj.id), JSON.stringify(obj))
       .map(res => res.json())
       .map((instance: any) => {
         if (instance) {
           return (this.fromJson(instance));
         }
         return null;
       }).subscribe(
         (data) => observable.next(data),
         (err) => observable.error(err),
         () => observable.complete()
       );
  });
Example #6
0
    addPerson(name: string) {
        var data = {
            Name: name
        };

        var headers = new Headers();
        headers.append('Content-Type', 'application/json');

        return this._http.post(
            'http://localhost:51523/api/home',
            JSON.stringify(data), {
                headers: headers
            });
    }
    login (username: string, password: string, profile: number): Observable<string>  {

        var loginData = [username, password, profile];
        let body = JSON.stringify(loginData);
        //let body = [username, password, profile];
        console.log("RequestBody = " + body);
        let headers = new Headers({ 'Content-Type': 'application/json' });
        let options = new RequestOptions({ headers: headers });

        return this.http.post(BackEndURL + '/login', body, options)
                        .map(this.extractData)
                        .catch(this.handleError);

    }
		return new Promise(resolve => {
			this.http.post(url, datatobepost, {
				headers: headers
			})
				.map(res => res.json())
				.subscribe(
				data => {
					resolve(data);
				},
				err => {
					resolve('Error');
				}
				);
		});
	addJSON(url: string, obj: any, cb: ServerResponse): void {

		let headers: Headers = new Headers();
		headers.append('Content-Type', 'application/json');

		let options: RequestOptions = new RequestOptions();
		options.headers = headers;

		this.http.post(url, JSON.stringify(obj), options)
			.subscribe((res: Response) => {
				cb(res.json());		//callBack		
            });	//http.post
        
	} 	//addJSON
Example #10
0
 anadirJugador(nombre:string, posicion:string, kda:number, equipo:number){
   let url = "https://localhost:8443/jugadores/";
   let item = { "nombre":nombre, "posicion":posicion, "media":kda, "equipo":{"id": equipo}
 };
 let body = JSON.stringify(item);
 let headers = new Headers({
   'Content-Type': 'application/json'
 });
 let options = new RequestOptions({ headers });
 return this.http.post(url, body, options)
     .map(response => response.json())
     .catch(error => this.manejarError(error)
   );
 }
  register(user: User) {
    var headers = new Headers();
    headers.append("Content-Type", "application/json");

    return this._http.post(
      Config.apiUrl + "Users",
      JSON.stringify({
        Username: user.email,
        Email: user.email,
        Password: user.password
      }),
      { headers: headers }
    );
  }
Example #12
0
  signin(signin: Signin) {

    let headers = new Headers();
    headers.append("Content-Type", "application/json");

    let body = {
      email: signin.email,
      password: signin.password
    };

    return this._http.post("/api/auth/signin", JSON.stringify(body), {headers: headers})
      .map((res: any) => res.json())
      .do((res: any) => { this._userService.setUserFromToken(res.token); });
  }
  addCategoryAttributes(attributeList:CharacteristicAttribute[], categoryId:string) {

    let transferData:any = JSON.stringify({attributeList:attributeList});
    let headers:Headers = this.getJsonHeader();

    let params:URLSearchParams = new URLSearchParams();
    params.set('categoryId', categoryId.toString());
    console.log('-----------------');
    console.log(transferData);

    return this.http.post('/api/category/addCategoryAttributes',transferData, {
      headers: headers,search: params
    }).map(res => res.json());
  }
    add(name: string) {
        var headers = new Headers();
        headers.append('Authorization', 'Bearer ' + Config.token);
        headers.append('Content-Type', 'application/json');

        return this._http.post(
            Config.apiUrl + 'Groceries',
            JSON.stringify({ Name: name }),
            { headers: headers })
            .map(res => res.json())
            .map(data => {
                return new Grocery(data.Result.Id, name);
            })
            .catch(this.handleErrors);
    }
Example #15
0
    saveDonor(donor: Donor) {
        var url = config.host + 'api/donors';
        var body = JSON.stringify(donor);
        var headers = new Headers();
        headers.append('Content-Type', 'application/json');

        var request: Observable<Response>;
        if (donor._id) {
            url += '/' + donor._id;
            request = this.http.put(url, body, { headers: headers });
        } else {
            request = this.http.post(url, body, { headers: headers });
        }
        return request.map(r => r.json());
    };
 refreshToken() {
   let token = localStorage.getItem('id_token');
   let body = JSON.stringify({ token: token });
   this.http.post('/api/token-refresh/', body, { headers: contentHeaders })
     .subscribe(
       response => {
         localStorage.setItem('id_token', response.json().token);
         this.router.parent.navigateByUrl('/home');
       },
       error => {
         alert(error.text());
         console.log(error.text());
       }
     );
 }
        // POST
        public addData(model: Alumno) {

            var obj = {
                '__metadata': { 'type': "SP.Data." + this.spListName + "ListItem" },
                'Nombre': model.nombre,
                'Apellidos': model.apellidos,
                'Nota': model.nota
            };
            // transformamos el objeto en string
            var data = JSON.stringify(obj);

            // hacemos la peticiĆ³n POST para  agregar el registro a la lista de SharePoint
            return this.http.post(this.spApiUrl + "/items", data, { headers: this.getHeaders("POST") }).map((res: Response) => res.json());
            
        }
 login(event, username, password) {
   event.preventDefault();
   let body = JSON.stringify({ name: username, password });
   this.http.post('http://localhost:8080/login', body, { headers: contentHeaders })
     .subscribe(
       response => {
         localStorage.setItem('jwt', response.json().idToken);
         this.router.parent.navigateByUrl('/home');
       },
       error => {
         alert(error.text());
         console.log(error.text());
       }
     );
 }
Example #19
0
 let uberPromise = new Promise((resolve, reject) => {
   console.log('hi from uber promise')
   this._http.post('/api/uber/journey', journey , {
         headers: headers
         })
         .map(res => res.json())
         .subscribe(
           data => {
               console.log('Promise from uberPromise ', data);
               resolve(data);
             }, 
           err => reject(err),
           () => console.log('uber received')
         );
 });
Example #20
0
 login(event, username, password) {
   event.preventDefault();
   let body = JSON.stringify({ username, password });
   this.http.post(this.config.getLoginUrl(), body, { headers: contentHeaders })
     .subscribe(
       response => {
         localStorage.setItem('jwt', response.json().id_token);
         this.router.parent.navigateByUrl('/');
       },
       error => {
         alert(error.text());
         console.log(error.text());
       }
     );
 }
   createNew(name: string) {

      return this._http.post(
        url,
        JSON.stringify({ name: name }),
        options
        )
        .map(res => res.json())
        .map(data => {
          let item = new Grocery();
          item.name = data.name;
          return item;
        })
        .catch(this.handleErrors);
   }
    authenticate(form) {

        let credentials = {
            email: form.value.email ? form.value.email : "",
            password: form.value.password ? form.value.password : ""
        };
        
        let headers = new Headers();
        headers.append('Content-Type', 'application/json');

        return this._http.post('/authenticate', JSON.stringify(credentials), {
            headers: headers
        }).map(res => res.json());

    }
 addItem(_item) {
   let url = KINVEY_BASE_URL + 'appdata/kid1781/todo-collection'
   let params = JSON.stringify(_item)
   return this.http.post(url, params, {
     headers: new Headers({
       'Content-Type': 'application/json',
       'Authorization': 'Kinvey ' + this.token,
       'X-Kinvey-API-Version': 3
     })
   })
     .map((res: any) => {
     let data = res.json();
     return data
   });
 }
 logout() {
   let params = JSON.stringify({});
    return this.http.post(KINVEY_BASE_URL + 'user/kid1781/_logout', params, {
      headers: new Headers({
        'Content-Type': 'application/json',
       'Authorization': 'Kinvey ' + this.token,
        'X-Kinvey-API-Version': 3
      })
    })
      .map((res: any) => {
      this.token = undefined;
      localStorage.removeItem('token');
      return true
    });
 }
    // PUT
    public putHistorial(historial: Historial) {

        var obj = {
            '__metadata': { 'type': 'SP.Data.EmpresaAlumnoListItem' },
            'DatosJson': historial.datosJson,
            'Terminado': historial.terminado,
            'EmpresasJson': historial.empresasJson,
            'AlumnosJson': historial.alumnosJson
        };



        var data = JSON.stringify(obj);
        return this.http.post(this.spApiUrl + "/_api/web/lists/getByTitle('EmpresaAlumno')/items(" + historial.id + ")", data, { headers: this.setHeaders("PUT") });
    }
 login(event, username, password) {
   event.preventDefault();
   let body = JSON.stringify({ name: username, password: password });
   this.http.post(Config.getInstance().getApiURL() + '/auth', body, { headers: contentHeaders })
     .subscribe(
       response => {
         localStorage.setItem('jwt', response.json().token);
         this.router.navigateByUrl('/app/users');
       },
       error => {
         alert(error.text());
         console.log(error.text());
       }
     );
 }
    postJson(){
      var json = JSON.stringify({
        title: 'foo',
        body: 'bar',
        userId: 1
      });
      var params = 'data=' + json;
      var header = new Headers();
      header.append('Content-type', 'application/x-www-form-urlencoded');

      return this._http.post("http://jsonplaceholder.typicode.com/posts",params, {
        headers:header
      })
      .map(res => res.json());
    };
Example #28
0
 makePost(): void {
   this.loading = true;
   this.http.post(
     "http://jsonplaceholder.typicode.com/posts",
     JSON.stringify({
       body: "bar",
       title: "foo",
       userId: 1
     }))
     .toRx()
     .subscribe((res: Response) => {
       this.data = res.json();
       this.loading = false;
     });
 }
Example #29
0
 postJsonTest() {
     var json = JSON.stringify({ something: 'test', somethingElse: 3 });
     var params = 'json=' + json;
     var headers = new Headers();
     headers.append('Content-Type', 'application/x-www-form-urlencoded)');
     
     headers.append('Access-Control-Allow-Origin', '*');
     headers.append('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, OPTIONS');
     headers.append('Accept', 'application/json');
     
     return this._http.post('http://validate.jsontest.com',
         params, 
         { headers: headers}) // optinal arguments
         .map(res => res.json());
 }
Example #30
0
 authenticate(userName: string, password: string) {
     let headers = new Headers();
     headers.append("Content-Type", "application/json");
     let body = { Name: userName, Identifier: password };
     return Promise.resolve(this.http.post(`/api/authenticate`, JSON.stringify(body), { headers: headers }).map(res => {
         var jsonResult = res.json();
         if (jsonResult.result === true) { //if authentication succeeded
             this.accService.setCredentials(userName, password); //set credentials of logged in user
             this.accService.loadKeys(jsonResult.keyStore); //load all keys for the user and friends
             this.authObserver.next(true); //change observer value to true (authenticated)
             this.accService.handleAnsweredRequests();
         }
         return jsonResult;
     }));
 }