Trying to utilize the API Service to fetch data and display the response as an object created by a class constructor
Currently executing a Typescript code that interacts with the API Service
import * as request from "request";
import { Users } from "./Users";
export class GitubHubApiService{
getUserInfo(username : String){
let options : any = {
headers:{
"User-Agent" :"request"
},
json : true
}
request.get("https://api.github.com/users/"+ username ,options,(error:any , Response : any,body: any) => {
console.log((body));
let user = new Users((body));
console.log(user);
})
}
}
This class forms the object using the response data from the API Service call.
export class Users{
login : String;
fullName : String;
repoCount : number;
followerCount : number;
constructor(userRes :any){
this.login = userRes.login;
this.fullName = userRes.name;
this.repoCount = userRes.public_repos;
this.followerCount = userRes.followers;
}
}
Users { login: undefined, fullName: undefined, repoCount: undefined, followerCount: undefined }