@molecule/app-http-inspector-angular 0.0.0-stage → 1.1.0
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/LICENSE +202 -0
- package/README.md +467 -2
- package/dist/http-inspector.component.d.ts +220 -0
- package/dist/http-inspector.component.d.ts.map +1 -0
- package/dist/http-inspector.component.js +555 -0
- package/dist/http-inspector.component.js.map +1 -0
- package/dist/index.d.ts +71 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +71 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +49 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +69 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,468 @@
|
|
|
1
|
-
|
|
1
|
+
<!--
|
|
2
|
+
AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
3
|
+
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
|
+
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
|
+
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
+
Generated: 2026-11-21T12:46:36.971Z
|
|
7
|
+
-->
|
|
2
8
|
|
|
3
|
-
|
|
9
|
+
# @molecule/app-http-inspector-angular
|
|
10
|
+
|
|
11
|
+
Angular HTTP request builder + response inspector — the counterpart of
|
|
12
|
+
`@molecule/app-http-inspector-react`: the same props and the same DOM for the
|
|
13
|
+
same input.
|
|
14
|
+
|
|
15
|
+
Exports `<HttpInspector>`, `HttpMethod`, `HttpHeader`, `HttpResponse` types.
|
|
16
|
+
|
|
17
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
18
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
19
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { Component, signal } from '@angular/core'
|
|
25
|
+
import { HttpInspector } from '@molecule/app-http-inspector-angular'
|
|
26
|
+
import type { HttpHeader, HttpMethod, HttpResponse } from '@molecule/app-http-inspector-angular'
|
|
27
|
+
|
|
28
|
+
@Component({
|
|
29
|
+
selector: 'app-inspector',
|
|
30
|
+
standalone: true,
|
|
31
|
+
imports: [HttpInspector],
|
|
32
|
+
template: `
|
|
33
|
+
<div
|
|
34
|
+
mol-http-inspector
|
|
35
|
+
[method]="method()"
|
|
36
|
+
(onMethodChange)="method.set($event)"
|
|
37
|
+
[url]="url()"
|
|
38
|
+
(onUrlChange)="url.set($event)"
|
|
39
|
+
[headers]="headers()"
|
|
40
|
+
(onHeadersChange)="headers.set($event)"
|
|
41
|
+
[body]="body()"
|
|
42
|
+
(onBodyChange)="body.set($event)"
|
|
43
|
+
[onSend]="send"
|
|
44
|
+
[sending]="sending()"
|
|
45
|
+
[response]="response()"
|
|
46
|
+
></div>
|
|
47
|
+
`,
|
|
48
|
+
})
|
|
49
|
+
export class Inspector {
|
|
50
|
+
readonly method = signal<HttpMethod>('GET')
|
|
51
|
+
readonly url = signal('https://api.example.com/v1/users')
|
|
52
|
+
readonly headers = signal<HttpHeader[]>([])
|
|
53
|
+
readonly body = signal('')
|
|
54
|
+
readonly sending = signal(false)
|
|
55
|
+
readonly response = signal<HttpResponse | null>(null)
|
|
56
|
+
|
|
57
|
+
async send() {
|
|
58
|
+
this.sending.set(true)
|
|
59
|
+
try {
|
|
60
|
+
// YOUR fetch here; then this.response.set(...)
|
|
61
|
+
} finally {
|
|
62
|
+
this.sending.set(false)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Type
|
|
69
|
+
|
|
70
|
+
`feature`
|
|
71
|
+
|
|
72
|
+
## Installation
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npm install @molecule/app-http-inspector-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## API
|
|
79
|
+
|
|
80
|
+
### Interfaces
|
|
81
|
+
|
|
82
|
+
#### `HttpHeader`
|
|
83
|
+
|
|
84
|
+
A single HTTP request or response header key/value pair.
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
interface HttpHeader {
|
|
88
|
+
key: string
|
|
89
|
+
value: string
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### `HttpResponse`
|
|
94
|
+
|
|
95
|
+
Parsed HTTP response returned after a request completes.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
interface HttpResponse {
|
|
99
|
+
statusCode: number
|
|
100
|
+
statusText?: string
|
|
101
|
+
durationMs?: number
|
|
102
|
+
body: string
|
|
103
|
+
headers?: HttpHeader[]
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
#### `HttpInspectorProps`
|
|
108
|
+
|
|
109
|
+
Inputs accepted by {@link HttpInspector} — the same props `@molecule/app-http-inspector-react` accepts.
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
interface HttpInspectorProps {
|
|
113
|
+
/** The request's HTTP method. */
|
|
114
|
+
method: HttpMethod
|
|
115
|
+
/** Called with the new method when the user picks one. */
|
|
116
|
+
onMethodChange: (method: HttpMethod) => void
|
|
117
|
+
/** The request URL. */
|
|
118
|
+
url: string
|
|
119
|
+
/** Called with the new URL as the user types. */
|
|
120
|
+
onUrlChange: (url: string) => void
|
|
121
|
+
/** The request headers, in render order. */
|
|
122
|
+
headers: HttpHeader[]
|
|
123
|
+
/** Called with the next header list on any header edit. */
|
|
124
|
+
onHeadersChange: (headers: HttpHeader[]) => void
|
|
125
|
+
/** The request body. */
|
|
126
|
+
body: string
|
|
127
|
+
/** Called with the new body as the user types. */
|
|
128
|
+
onBodyChange: (body: string) => void
|
|
129
|
+
/** Sends the request; the app owns the fetch and the response state. */
|
|
130
|
+
onSend: () => void | Promise<void>
|
|
131
|
+
/** Whether a send is in flight (disables the Send button, shows `Sending…`). */
|
|
132
|
+
sending?: boolean
|
|
133
|
+
/** The last response to show, or `null`/absent for none. */
|
|
134
|
+
response?: HttpResponse | null
|
|
135
|
+
/** Extra classes on the outer wrapper. */
|
|
136
|
+
className?: string
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Types
|
|
141
|
+
|
|
142
|
+
#### `HttpMethod`
|
|
143
|
+
|
|
144
|
+
HTTP method verb for a request.
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS'
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Classes
|
|
151
|
+
|
|
152
|
+
#### `HttpInspector`
|
|
153
|
+
|
|
154
|
+
HttpInspector component.
|
|
155
|
+
|
|
156
|
+
Controlled HTTP request builder + response panel. The host IS the outer
|
|
157
|
+
`<div>` React renders (`div[mol-http-inspector]`), with the same classes.
|
|
158
|
+
App owns request state + the actual `fetch`; this component renders the UI:
|
|
159
|
+
method + URL row, headers key/value editor, body textarea (methods that
|
|
160
|
+
allow a body), Send button, then a response panel showing status + timing +
|
|
161
|
+
body.
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
@Component({
|
|
165
|
+
selector: 'div[mol-http-inspector]',
|
|
166
|
+
standalone: true,
|
|
167
|
+
imports: [Button, Input, Select, Textarea],
|
|
168
|
+
inputs: [
|
|
169
|
+
'method',
|
|
170
|
+
'onMethodChange',
|
|
171
|
+
'url',
|
|
172
|
+
'onUrlChange',
|
|
173
|
+
'headers',
|
|
174
|
+
'onHeadersChange',
|
|
175
|
+
'body',
|
|
176
|
+
'onBodyChange',
|
|
177
|
+
'onSend',
|
|
178
|
+
'sending',
|
|
179
|
+
'response',
|
|
180
|
+
'className',
|
|
181
|
+
],
|
|
182
|
+
host: {
|
|
183
|
+
'[class]': 'classes()',
|
|
184
|
+
},
|
|
185
|
+
// prettier-ignore
|
|
186
|
+
template: `<div [class]="rowClasses()"
|
|
187
|
+
><!-- The options are protocol tokens (GET, POST, …): never translated, so the element carries HTML's own translate="no" attribute. --><div
|
|
188
|
+
mol-select
|
|
189
|
+
[id]="'http-inspector-method'"
|
|
190
|
+
[options]="methodOptions"
|
|
191
|
+
[value]="method"
|
|
192
|
+
(valueChange)="handleMethodChange($event)"
|
|
193
|
+
translate="no"
|
|
194
|
+
[attr.aria-label]="methodLabel()"
|
|
195
|
+
></div
|
|
196
|
+
><!-- The placeholder is an example URL — input, not prose: never translated. --><div
|
|
197
|
+
mol-input
|
|
198
|
+
[id]="'http-inspector-url'"
|
|
199
|
+
[type]="'text'"
|
|
200
|
+
[value]="url"
|
|
201
|
+
(change)="handleUrlChange($event)"
|
|
202
|
+
placeholder="https://api.example.com/v1/resources"
|
|
203
|
+
translate="no"
|
|
204
|
+
[className]="flexClasses()"
|
|
205
|
+
[attr.aria-label]="urlLabel()"
|
|
206
|
+
></div
|
|
207
|
+
><button
|
|
208
|
+
mol-button
|
|
209
|
+
[variant]="'solid'"
|
|
210
|
+
[color]="'primary'"
|
|
211
|
+
(click)="send()"
|
|
212
|
+
[disabled]="!!sending"
|
|
213
|
+
>{{ sending ? sendingText() : sendText() }}</button
|
|
214
|
+
></div>
|
|
215
|
+
<div [class]="stack1Classes()"><span [class]="labelClasses()">{{ headersLabel() }}</span>
|
|
216
|
+
@for (header of headers; track $index) {
|
|
217
|
+
<div [class]="headerRowClasses()"
|
|
218
|
+
><div
|
|
219
|
+
mol-input
|
|
220
|
+
[id]="'http-inspector-header-' + $index + '-key'"
|
|
221
|
+
[type]="'text'"
|
|
222
|
+
[value]="header.key"
|
|
223
|
+
(change)="handleHeaderKey($index, $event)"
|
|
224
|
+
[placeholder]="headerPlaceholder()"
|
|
225
|
+
></div
|
|
226
|
+
><div
|
|
227
|
+
mol-input
|
|
228
|
+
[id]="'http-inspector-header-' + $index + '-value'"
|
|
229
|
+
[type]="'text'"
|
|
230
|
+
[value]="header.value"
|
|
231
|
+
(change)="handleHeaderValue($index, $event)"
|
|
232
|
+
[placeholder]="valuePlaceholder()"
|
|
233
|
+
[className]="flexClasses()"
|
|
234
|
+
></div
|
|
235
|
+
><button mol-button [variant]="'ghost'" [size]="'sm'" (click)="removeHeader($index)">×</button
|
|
236
|
+
></div>
|
|
237
|
+
}
|
|
238
|
+
<button mol-button [variant]="'ghost'" [size]="'sm'" (click)="addHeader()">+ {{ addHeaderLabel() }}</button>
|
|
239
|
+
</div>
|
|
240
|
+
@if (showBody()) {
|
|
241
|
+
<div [class]="stack1Classes()"><span [class]="labelClasses()">{{ bodyLabel() }}</span><!-- The placeholder is a JSON example — input, not prose: never translated. --><div
|
|
242
|
+
mol-textarea
|
|
243
|
+
[id]="'http-inspector-body'"
|
|
244
|
+
[value]="body"
|
|
245
|
+
(change)="handleBodyChange($event)"
|
|
246
|
+
[rows]="6"
|
|
247
|
+
[placeholder]="bodyPlaceholder"
|
|
248
|
+
translate="no"
|
|
249
|
+
></div></div>
|
|
250
|
+
}
|
|
251
|
+
@if (response; as resp) {
|
|
252
|
+
<div [class]="stack2Classes()">
|
|
253
|
+
<div [class]="rowClasses()"
|
|
254
|
+
><span [class]="statusClasses(resp.statusCode)" [style]="statusStyle()">{{ resp.statusCode }} {{ resp.statusText ?? '' }}</span
|
|
255
|
+
>@if (resp.durationMs !== undefined) {<span [class]="textXsClasses()">{{ resp.durationMs }}ms</span>}</div
|
|
256
|
+
><pre [class]="preClasses()" [style]="preStyle()">@if (resp.body !== '') {<ng-container>{{ resp.body }}</ng-container>}</pre>
|
|
257
|
+
</div>
|
|
258
|
+
}`,
|
|
259
|
+
})
|
|
260
|
+
export class HttpInspector {
|
|
261
|
+
/** The request's HTTP method. */
|
|
262
|
+
method: HttpMethod = 'GET'
|
|
263
|
+
onMethodChange?: (method: HttpMethod) => void
|
|
264
|
+
/** The request URL. */
|
|
265
|
+
url = ''
|
|
266
|
+
onUrlChange?: (url: string) => void
|
|
267
|
+
/** The request headers, in render order. */
|
|
268
|
+
headers: HttpHeader[] = []
|
|
269
|
+
onHeadersChange?: (headers: HttpHeader[]) => void
|
|
270
|
+
/** The request body. */
|
|
271
|
+
body = ''
|
|
272
|
+
onBodyChange?: (body: string) => void
|
|
273
|
+
/** Sends the request (React's `onSend`). */
|
|
274
|
+
onSend?: () => void | Promise<void>
|
|
275
|
+
/** Whether a send is in flight (React's `sending`). */
|
|
276
|
+
sending?: boolean
|
|
277
|
+
/** The last response to show (React's `response`). */
|
|
278
|
+
response?: HttpResponse | null
|
|
279
|
+
className?: string
|
|
280
|
+
|
|
281
|
+
/** The method options, in React's order. */
|
|
282
|
+
readonly methodOptions = METHODS.map((method) => ({ value: method, label: method }))
|
|
283
|
+
|
|
284
|
+
/** The body textarea's placeholder (React's literal). */
|
|
285
|
+
readonly bodyPlaceholder = '{"key": "value"}'
|
|
286
|
+
|
|
287
|
+
/** Reactive translation, read in the injection context. */
|
|
288
|
+
private readonly i18n = useTranslation()
|
|
289
|
+
|
|
290
|
+
/** The current class map. */
|
|
291
|
+
cm(): UIClassMap {
|
|
292
|
+
return getClassMap()
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
classes(): string {
|
|
296
|
+
return this.cm().cn(this.cm().stack(3), this.className)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
rowClasses(): string {
|
|
300
|
+
return this.cm().flex({ align: 'center', gap: 'sm' })
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
headerRowClasses(): string {
|
|
304
|
+
return this.cm().flex({ align: 'center', gap: 'xs' })
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
stack1Classes(): string {
|
|
308
|
+
return this.cm().stack(1)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** The response section's class (React's `cm.stack(2)`). */
|
|
312
|
+
stack2Classes(): string {
|
|
313
|
+
return this.cm().stack(2)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
labelClasses(): string {
|
|
317
|
+
return this.cm().cn(this.cm().textSize('xs'), this.cm().fontWeight('semibold'))
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
textXsClasses(): string {
|
|
321
|
+
return this.cm().textSize('xs')
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
preClasses(): string {
|
|
325
|
+
return this.cm().cn(this.cm().sp('p', 3), this.cm().textSize('xs'))
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/** The URL input's extra class (React's `cm.flex1`). */
|
|
329
|
+
flexClasses(): string {
|
|
330
|
+
return this.cm().flex1
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
statusClasses(code: number): string {
|
|
334
|
+
return this.cm().cn(this.cm().bgTone(statusTone(code)), this.cm().textOnTone)
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
statusStyle(): Record<string, string> {
|
|
338
|
+
return {
|
|
339
|
+
padding: '2px 8px',
|
|
340
|
+
'border-radius': '4px',
|
|
341
|
+
'font-weight': '700',
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
preStyle(): Record<string, string> {
|
|
346
|
+
return { 'overflow-x': 'auto' }
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
showBody(): boolean {
|
|
350
|
+
return this.method !== 'GET' && this.method !== 'HEAD'
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
sendingText(): string {
|
|
354
|
+
return this.i18n.t('httpInspector.sending', {}, { defaultValue: 'Sending…' })
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
sendText(): string {
|
|
358
|
+
return this.i18n.t('httpInspector.send', {}, { defaultValue: 'Send' })
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
headersLabel(): string {
|
|
362
|
+
return this.i18n.t('httpInspector.headers', {}, { defaultValue: 'Headers' })
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
bodyLabel(): string {
|
|
366
|
+
return this.i18n.t('httpInspector.body', {}, { defaultValue: 'Body' })
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
addHeaderLabel(): string {
|
|
370
|
+
return this.i18n.t('httpInspector.addHeader', {}, { defaultValue: 'Add header' })
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
methodLabel(): string {
|
|
374
|
+
return this.i18n.t('httpInspector.methodLabel', {}, { defaultValue: 'HTTP method' })
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
urlLabel(): string {
|
|
378
|
+
return this.i18n.t('httpInspector.urlLabel', {}, { defaultValue: 'URL' })
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
headerPlaceholder(): string {
|
|
382
|
+
return this.i18n.t('httpInspector.headerPlaceholder', {}, { defaultValue: 'Header' })
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
valuePlaceholder(): string {
|
|
386
|
+
return this.i18n.t('httpInspector.valuePlaceholder', {}, { defaultValue: 'Value' })
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/** Reports a picked method (React's `onMethodChange`). */
|
|
390
|
+
handleMethodChange(method: string): void {
|
|
391
|
+
this.onMethodChange?.(method as HttpMethod)
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/** Adopts the typed URL (React's `onUrlChange`). */
|
|
395
|
+
handleUrlChange(event: Event): void {
|
|
396
|
+
this.onUrlChange?.((event.target as HTMLInputElement).value)
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
handleHeaderKey(i: number, event: Event): void {
|
|
400
|
+
const next = [...this.headers]
|
|
401
|
+
next[i] = { key: (event.target as HTMLInputElement).value, value: next[i].value }
|
|
402
|
+
this.onHeadersChange?.(next)
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
handleHeaderValue(i: number, event: Event): void {
|
|
406
|
+
const next = [...this.headers]
|
|
407
|
+
next[i] = { key: next[i].key, value: (event.target as HTMLInputElement).value }
|
|
408
|
+
this.onHeadersChange?.(next)
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
removeHeader(i: number): void {
|
|
412
|
+
this.onHeadersChange?.(this.headers.filter((_, j) => j !== i))
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
addHeader(): void {
|
|
416
|
+
this.onHeadersChange?.([...this.headers, { key: '', value: '' }])
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/** Adopts the typed body (React's `onBodyChange`). */
|
|
420
|
+
handleBodyChange(event: Event): void {
|
|
421
|
+
this.onBodyChange?.((event.target as HTMLTextAreaElement).value)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
send(): void {
|
|
425
|
+
void this.onSend?.()
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
_(Member comments are shortened to their first sentence, and the 30 longest are left out to fit; the full declaration is in `node_modules/@molecule/app-http-inspector-angular/dist/http-inspector.component.d.ts`.)_
|
|
431
|
+
|
|
432
|
+
## Injection Notes
|
|
433
|
+
|
|
434
|
+
### Requirements
|
|
435
|
+
|
|
436
|
+
Peer dependencies:
|
|
437
|
+
|
|
438
|
+
- `@angular/common` ^22.0.0
|
|
439
|
+
- `@angular/core` ^22.0.0
|
|
440
|
+
- `@angular/platform-browser` ^22.0.0
|
|
441
|
+
- `@molecule/app-angular` ^3.5.0
|
|
442
|
+
- `@molecule/app-ui` ^1.4.0
|
|
443
|
+
- `@molecule/app-ui-angular` ^1.1.0
|
|
444
|
+
|
|
445
|
+
### Runtime Dependencies
|
|
446
|
+
|
|
447
|
+
- `@angular/common`
|
|
448
|
+
- `@angular/core`
|
|
449
|
+
- `@angular/platform-browser`
|
|
450
|
+
- `@molecule/app-angular`
|
|
451
|
+
- `@molecule/app-ui`
|
|
452
|
+
- `@molecule/app-ui-angular`
|
|
453
|
+
|
|
454
|
+
- Fully controlled and transport-agnostic: the component renders the
|
|
455
|
+
builder UI only — YOUR `onSend` performs the fetch and sets `response`
|
|
456
|
+
(`HttpResponse` with statusCode/durationMs/body). `sending` disables the
|
|
457
|
+
Send button.
|
|
458
|
+
- Requires the Angular binding's i18n provider (`useTranslation()` THROWS
|
|
459
|
+
without it) and a bonded ClassMap; button/tab labels come from the
|
|
460
|
+
`@molecule/app-locales-http-inspector` companion bond.
|
|
461
|
+
- The body editor renders only for methods with bodies (hidden for GET and
|
|
462
|
+
HEAD).
|
|
463
|
+
- The response status chip uses fixed severity colors (green/blue/
|
|
464
|
+
yellow/red) rendered inline — they do not follow the app theme.
|
|
465
|
+
|
|
466
|
+
## Translations
|
|
467
|
+
|
|
468
|
+
Translation strings are provided by `@molecule/app-locales-http-inspector`.
|