You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
* the [security flaw](http://stackoverflow.com/questions/3503102/what-are-top-level-json-arrays-and-why-are-they-a-security-risk)
31
-
that data encapsulation tried to overcome has been fixed in most (if not all) browsers supported by Angular v2+.
32
-
* data encapsulation is uncommon in modern web APIs.
33
-
* removing the `.map` step simplifies usage of `HttpClient` in most scenarios.
30
+
31
+
1. Almost everyone seems to hate the encapsulation
32
+
33
+
2. Encapsulation requires mapping to get the desired data out. With old `Http` that isn't _too_ bad because you needed to map to get data anyway (`res => res.json()`). But it is really ugly for `HttpClient` because you can't use the type HTTP method type parameter (e.g., `get<entity-type>`) and you have to map out of the data property (`.map(data => data.data as Hero[]`). That extra step requires explanations that distract from learning `HttpClient` itself.
34
+
Now you just write `http.get<Hero[]>()` and you’ve got data (please add error handling).
35
+
36
+
3. While you could have turned off encapsulation with configuration as of v.0.4, to do so took yet another step that you’d have to discover and explain. A big reason for the in-mem web api is to make it easy to introduce and demonstrate HTTP operations in Angular. The _out-of-box_ experience is more important than avoiding a breaking change.
37
+
38
+
4. The [security flaw](http://stackoverflow.com/questions/3503102/what-are-top-level-json-arrays-and-why-are-they-a-security-risk)
39
+
that prompted encapsulation seems to have been mitigated by all (almost all?) the browsers that can run an Angular (v2+) app. We don’t think it’s needed anymore.
40
+
41
+
5. A most real world APIs today will not encapsulate; they’ll return the data in the body without extra ceremony.
0 commit comments