I\'m improving an existing API, and the requirement is to provide a single get method which can accept multiple search criteria and based on those criteria perform the query
This worked for me:
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
filterBooks(category: string, year: string): Observable {
let httpHeaders = new HttpHeaders()
.set('Accept', 'application/json');
let httpParams = new HttpParams()
.set('category', category)
.set('year', year);
console.log(httpParams.toString());
console.log(httpHeaders.keys());
return this.http.get(this.bookUrl, {
headers: httpHeaders,
params: httpParams,
responseType: 'json'
});
}