I am trying to use Zillow API which has XSD file.
API - https://www.zillow.com/howto/api/GetDeepSearchResults.htm
this has http://www.zillow.com/static/xsd/SearchResults.xsd
const data = <User>{
name: 'sds',
email: '[email protected]',
phone: '(434)-354-5454',
address: '126 Hopkins Ave',
city: 'Jersey City',
state: 'NJ',
zipcode: '07306'
};
API request call is done using api.service.ts
getZillowSearchResultAPI(user: User) {
return
this.http.get(`http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=X1-ZWz1gdddouj9jf_adn99&address=
${user.address}&rentzestimate=YES&citystatezip=${user.city}%2C${user.state}%2C${user.zipcode}`,
{responseType: 'text'});
}
this.adminApiService.addUser(data)
.subscribe((result: any) => {
//this.zillowObject = result.response.results.result.zestimate;
});
I want to know how do i get response back from API call?
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
import {Component, OnInit} from '@angular/core';
import {AdminApiService} from './admin-api.service';
import {User} from '../common/user';
import {MatDialog, MatDialogConfig, MatSnackBar} from '@angular/material';
import {AddUserComponent} from '../add-user/add-user.component';
@Component({
selector: 'admin-layout',
templateUrl: './admin.component.html',
styleUrls: ['./admin.component.scss']
})
export class AdminComponent implements OnInit {
title = 'RaghuSite';
displayedColumns = ['id', 'name', 'email', 'phone', 'address', 'active', 'ipadd', 'actions'];
users: Array<User>;
constructor(private adminApiService: AdminApiService,
private snackBar: MatSnackBar,
public dialog: MatDialog) {
}
ngOnInit() {
this.getUsres();
}
getUsres() {
this.adminApiService.getUsers()
.subscribe((users: Array<User>) => {
this.users = users;
});
}
deleteUser(user: User) {
this.adminApiService.deleteUser(user.id)
.subscribe(() => {
this.getUsres();
this.snackBar.open('User record deleted.', 'Ok', {duration: 5000});
});
}
addUser() {
const dialogRef = this.dialog.open(AddUserComponent, <MatDialogConfig>{
width: '40vw',
disableClose: true,
hasBackdrop: true,
role: 'dialog',
});
dialogRef.afterClosed()
.subscribe(() => {
this.getUsres();
});
}
}
import {Injectable} from '@angular/core';
import {Config} from '../config/config';
import {User} from '../common/user';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/merge';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import {toJson} from 'xml2json';
@Injectable()
export class AdminApiService {
private BASE_URI: string;
constructor(private http: HttpClient, private config: Config) {
this.BASE_URI = config.getHost();
}
getUsers() {
return this.http.get(`${this.BASE_URI}/user`);
}
deleteUser(id: number) {
return this.http.delete(`${this.BASE_URI}/user/${id}`);
}
addUser(user: User) {
return this.http.post(`${this.BASE_URI}/user`, user);
}
getZillowSearchResultAPI(user: User) {
return this.http.get(`http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=X1-ZWz1gdddouj9jf_adn99&address=
${user.address}&rentzestimate=YES&citystatezip=${user.city}%2C${user.state}%2C${user.zipcode}`, {responseType: 'text'});
}
private handleError(error: HttpErrorResponse): Observable<any> {
console.error('observable error: ', error);
return Observable.throw(error);
}
}
export interface User {
id?: number;
name: string;
email: string;
phone: string;
address: string;
city: string;
state: string;
zipcode: string;
rentfrom: number;
rentto: number;
userrent: number;
ipadd: string;
active: boolean;
}