Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit c5a83c1

Browse files
committed
docs: CHANGELOG - clarify reasons for no encapsulation default
1 parent cc02859 commit c5a83c1

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

CHANGELOG.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,18 @@ HttpClientInMemoryWebApiModule.forRoot(HeroInMemDataService, { dataEncapsulation
2727
```
2828

2929
We made this change because
30-
* 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.
3442

3543
<a id="0.4.6"></a>
3644
## 0.4.6 (2017-09-13)

0 commit comments

Comments
 (0)