Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
Default response type get request angular

I have a service like

getOrganizationsFile() {
return this.http.get(`${this.baseUrl}/export`, {
  responseType: 'blob',
  observe: 'response',
});

}

and I call it in the TS file like

downloadOrganizationsFile() {
this.orgService.getOrganizationsFile().subscribe((res) => {
  CommonUtil.saveFile(res)
});

}

and I save the response and download it

static saveFile(res: any) {
const fileName = res.headers.get('content-disposition').split(';')[1].split('=')[1].replace(/\"/g, '');
saveAs(res.body, fileName);

}

My question is in the saveFile method I pass res as parameter, I dont want to use type 'any'.

The response I get from the server is like enter image description here

is there an default response type in Angular, like 'HttpResponse' so that I can put a type for it instead of using 'any'.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

There is a default HttpResponse imported like this:

import {HttpResponse} from @angular/common/http

Read more about it on -> https://angular.io/api/common/http/HttpResponse

about 4 years ago · Juan Pablo Isaza Report

0

You want to create your own model based on what the server side is returning.

org-file.model.ts

export interface OrgFile {
  ...
}
getOrganizationsFile(): Observable<OrgFile> {
return this.http.get<OrgFile>(`${this.baseUrl}/export`, {
  responseType: 'blob',
  observe: 'response',
});
static saveFile(res: OrgFile) {
const fileName = res.headers.get('content-disposition').split(';')[1].split('=')[1].replace(/\"/g, '');
saveAs(res.body, fileName);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!