@unireq/xml 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# @unireq/xml
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@unireq/xml)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
XML parsing and serialization built on top of `fast-xml-parser`. Drop-in policies for SOAP-style or mixed JSON/XML APIs.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pnpm add @unireq/xml
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Quick Start
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import { client } from '@unireq/core';
|
|
18
|
+
import { http, headers } from '@unireq/http';
|
|
19
|
+
import { xml } from '@unireq/xml';
|
|
20
|
+
|
|
21
|
+
const api = client(
|
|
22
|
+
http('https://api.example.com'),
|
|
23
|
+
headers({ accept: 'application/xml' }),
|
|
24
|
+
xml({ ignoreAttributes: false, attributeNamePrefix: '@_' }),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const res = await api.get('/orders/123');
|
|
28
|
+
console.log(res.data.order.total);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
| Symbol | Description |
|
|
34
|
+
| --- | --- |
|
|
35
|
+
| `xml(options?)` | Response policy that parses XML to JS objects |
|
|
36
|
+
| `xmlBody(data, options?)` | Body descriptor for XML serialization |
|
|
37
|
+
| `XMLParserOptions` | Re-exported parser configuration types |
|
|
38
|
+
| `XMLBuilderOptions` | Re-exported builder configuration types |
|
|
39
|
+
|
|
40
|
+
## Serializing Requests
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { xmlBody } from '@unireq/xml';
|
|
44
|
+
|
|
45
|
+
await api.post('/invoices', xmlBody(
|
|
46
|
+
{ invoice: { id: 42, total: 99.9 } },
|
|
47
|
+
{ format: true, indentBy: ' ' },
|
|
48
|
+
));
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## JSON/XML Negotiation
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { client, either } from '@unireq/core';
|
|
55
|
+
import { http, parse } from '@unireq/http';
|
|
56
|
+
import { xml } from '@unireq/xml';
|
|
57
|
+
|
|
58
|
+
const api = client(
|
|
59
|
+
http('https://hybrid.example.com'),
|
|
60
|
+
either(
|
|
61
|
+
(ctx) => ctx.headers.accept?.includes('json') ?? false,
|
|
62
|
+
parse.json(),
|
|
63
|
+
xml(),
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Tips
|
|
69
|
+
|
|
70
|
+
- **Error handling**: Wrap with `retry` if malformed XML is possible
|
|
71
|
+
- **Streaming**: Policy buffers full body before parsing
|
|
72
|
+
- **Namespaces**: Use `ignoreNameSpace`/`removeNSPrefix` for SOAP
|
|
73
|
+
|
|
74
|
+
## Documentation
|
|
75
|
+
|
|
76
|
+
Full documentation available at [unireq.dev](https://oorabona.github.io/unireq/)
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unireq/xml",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "XML parser policy for unireq",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"author": "Olivier Orabona",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@unireq/core": "1.0.
|
|
20
|
+
"@unireq/core": "1.0.1"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"fast-xml-parser": "^4.5.0"
|