Skip to content

Commit e2150f2

Browse files
razor-xseambot
andauthored
docs: Add Motivation (#3)
* Add Motivation * ci: Format code * Fix sentence * Fix typo * Merge paragraphs --------- Co-authored-by: Seam Bot <[email protected]>
1 parent 3eb3499 commit e2150f2

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,41 @@ Serializes JavaScript objects to URLSearchParams.
99

1010
Defines the standard for how the Seam SDKs and other Seam API consumers
1111
should serialize objects to [URLSearchParams] in HTTP GET requests.
12-
1312
Serves as a reference implementation for Seam SDKs in other languages.
1413

1514
See this test for the [serialization behavior](./test/serialization.test.ts).
1615

1716
[URLSearchParams]: https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
1817

18+
## Motivation
19+
20+
URL search parameters are strings, however the Seam API will parse parameters as complex types.
21+
The Seam SDK must accept the complex types as input and serialize these
22+
to search parameters in a way supported by the Seam API.
23+
24+
There is no single standard for this serialization.
25+
This module establishes the serialization standard adopted by the Seam API.
26+
27+
### Why not use [URLSearchParams](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)?
28+
29+
Passing a raw object to URLSearchParams has unpredictable serialization behavior.
30+
31+
### Why not [qs](https://github.com/ljharb/qs)?
32+
33+
- Not a zero-dependency module. Has quite a few dependency layers.
34+
- Impractile as a reference implementation.
35+
Since qs enables complex, non-standard parsing and serialization,
36+
this makes ensuing SDK parity much harder.
37+
Similarly, this puts an unreasonable burden on User's of the HTTP API or those implementing their own client.
38+
- The Seam API must ensure it handles a well defined set of non-string query parameters consistency.
39+
Using qs would allow the SDK to send unsupported or incorrectly serialized parameter types to the API
40+
resulting in unexpected behavior.
41+
42+
### Why not use the default [Axios](https://axios-http.com/) serializer?
43+
44+
Using the default [Axios] serializer was the original approach,
45+
however it had similar issues to using URLSearchParams and qs as noted above.
46+
1947
## Installation
2048

2149
Add this as a dependency to your project using [npm] with

0 commit comments

Comments
 (0)