When making a GET request, I need to include parameters: offset: <number>
, limit: <number>
, and an optional parameter sortBy
that accepts fields separated by commas.
What is the best way to define the GET method?
getData(limit: number, offset: number, sortBy?: string) {
return this.http.get("");
}
interface Request {
limit: number;
offset: number;
sortBy: string;
}
getData(request: Request) {
return this.http.get("");
}
Alternatively:
interface Request {
limit: number;
offset: number;
sortBy: string[];
}
getData(request: Request) {
const sortBy = request.sortBy.split(",");
return this.http.get("");
}