Does Angular API only call requested data?

I am making an api call and want make sure I am reducing data transfer as much as possible.

on the Angular end I have a request:


Where RecordSummary is:

export interface RecordSummary
    Id: number;
    Name: string;   

Now my API endpoint retuns a Full Record:

public class FulLRecord {
    public int Id { get; set; }
    public string Name { get; set; }
    public string Age { get; set; }
    public Color Color { get; set; }

When I make the call, does the entire Full Record get transferred over the call or just the requested fields? My understanding so far is that it is the full record, but wanted to make sure.

>Solution :

When you make this call:


You’re specifying that you want to deserialize the JSON you receive and use it as a RecordSummary object. It does not communicate this object structure to the API, so you will still be receiving the full object that the API sends.

You can confirm this by looking at the network request in your browser’s developer tools window. For Chrome you can open this by pressing F12.

Please also note that you’re dealing with TypeScript which still gets converted to JavaScript when you "build" it, so although your statically typed code has a RecordSummary object, the actual object in-memory will have more data in it if the API sent more. You can observe this by casting it to any and then accessing one of the properties:

let result = http.get<RecordSummary>(url);
let fullObject = <any>result;

This will show an alert with the Age that was received from the API.

Leave a Reply