vue-api-request-builder 0.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/README.md ADDED
@@ -0,0 +1,188 @@
1
+ # API Request Builder
2
+
3
+ A Vue 3 component for building and testing API requests with a beautiful UI.
4
+
5
+ # Start of Selection
6
+ [中文文档](README_zh.md)
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install vue-api-request-builder
12
+ # or
13
+ yarn add vue-api-request-builder
14
+ # or
15
+ pnpm add vue-api-request-builder
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ### Basic Usage
21
+
22
+ ```vue
23
+ <template>
24
+ <RequestForm v-model="requestSchema" @update:modelValue="handleSchemaChange" />
25
+ <ResponseSection v-model="requestSchema" />
26
+ </template>
27
+
28
+ <script setup lang="ts">
29
+ import { ref } from 'vue';
30
+ import { RequestForm, ResponseSection, type RequestSchema, defaultRequestSchema } from 'vue-api-request-builder';
31
+
32
+ const requestSchema = ref<RequestSchema>(defaultRequestSchema);
33
+
34
+ const handleSchemaChange = (newSchema: RequestSchema) => {
35
+ console.log("Schema changed:", newSchema);
36
+ };
37
+ </script>
38
+ ```
39
+
40
+ ### Advanced Usage with Preview
41
+
42
+ ```vue
43
+ <template>
44
+ <div class="app-container">
45
+ <RequestForm v-model="requestSchema" @update:modelValue="handleSchemaChange" />
46
+ <ResponseSection v-model="requestSchema" />
47
+ </div>
48
+ </template>
49
+
50
+ <script setup lang="ts">
51
+ import { ref, watch } from 'vue';
52
+ import { RequestForm, ResponseSection, type RequestSchema, defaultRequestSchema } from 'vue-api-request-builder';
53
+
54
+ const requestSchema = ref<RequestSchema>(defaultRequestSchema);
55
+
56
+ const handleSchemaChange = (newSchema: RequestSchema) => {
57
+ console.log("Schema changed:", newSchema);
58
+ };
59
+ </script>
60
+ ```
61
+
62
+ ## Components
63
+
64
+ ### RequestForm
65
+
66
+ The main component for building API requests. It provides a form interface for configuring:
67
+
68
+ #### Props
69
+ - `modelValue` (RequestSchema): The request schema object (v-model)
70
+
71
+ #### Events
72
+ - `update:modelValue`: Emitted when the schema changes
73
+
74
+ #### Features
75
+ - HTTP method selection (GET, POST, PUT, DELETE, OPTIONS)
76
+ - URL configuration with base URL and path
77
+ - URL parameters management
78
+ - Authentication options:
79
+ - None
80
+ - Basic Auth
81
+ - Bearer Token
82
+ - Custom headers
83
+ - Request body support for:
84
+ - JSON
85
+ - Form Data
86
+ - Raw text
87
+ - Live preview of request URL and body
88
+
89
+ ### ResponseSection
90
+
91
+ Displays the response from the API request.
92
+
93
+ #### Props
94
+ - `modelValue` (RequestSchema): The request schema object (v-model)
95
+
96
+ #### Features
97
+ - Request method selection (XMLHttpRequest/Fetch)
98
+ - Response display:
99
+ - Status code with color coding
100
+ - Response time
101
+ - Response headers
102
+ - Response body with formatting
103
+ - Error handling and display
104
+
105
+ ### KeyValueInput
106
+
107
+ A reusable component for managing key-value pairs.
108
+
109
+ #### Props
110
+ - `modelValue` (KeyValuePair[]): Array of key-value pairs (v-model)
111
+ - `addButtonText` (string): Text for the add button
112
+ - `showPreview` (boolean): Whether to show the preview
113
+ - `previewText` (string): Text to show in preview
114
+
115
+ #### Events
116
+ - `update:modelValue`: Emitted when the key-value pairs change
117
+
118
+ ## Types
119
+
120
+ ### RequestSchema
121
+
122
+ ```typescript
123
+ interface RequestSchema {
124
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'OPTIONS';
125
+ url: string;
126
+ path: string;
127
+ auth: AuthConfig;
128
+ params: KeyValuePair[];
129
+ headers: KeyValuePair[];
130
+ body: RequestBody;
131
+ }
132
+ ```
133
+
134
+ ### AuthConfig
135
+
136
+ ```typescript
137
+ interface AuthConfig {
138
+ type: 'none' | 'Basic' | 'Bearer';
139
+ username?: string;
140
+ password?: string;
141
+ token?: string;
142
+ }
143
+ ```
144
+
145
+ ### RequestBody
146
+
147
+ ```typescript
148
+ interface RequestBody {
149
+ type: 'application/json' | 'multipart/form-data' | 'text/plain';
150
+ json?: string;
151
+ formData?: KeyValuePair[];
152
+ raw?: string;
153
+ }
154
+ ```
155
+
156
+ ### ResponseData
157
+
158
+ ```typescript
159
+ interface ResponseData {
160
+ status: string;
161
+ headers: Record<string, string>;
162
+ body: string;
163
+ timing?: number;
164
+ }
165
+ ```
166
+
167
+ ## Utilities
168
+
169
+ ### executeRequest
170
+
171
+ ```typescript
172
+ function executeRequest(
173
+ schema: RequestSchema,
174
+ method: 'fetch' | 'xhr' = 'xhr'
175
+ ): Promise<ResponseData>
176
+ ```
177
+
178
+ Executes the API request using either Fetch API or XMLHttpRequest.
179
+
180
+ ## Dependencies
181
+
182
+ This package requires:
183
+ - Vue 3.x
184
+ - Ant Design Vue 4.x
185
+
186
+ ## License
187
+
188
+ MIT
@@ -0,0 +1,84 @@
1
+ import { ComponentOptionsMixin } from 'vue';
2
+ import { ComponentProvideOptions } from 'vue';
3
+ import { DefineComponent } from 'vue';
4
+ import { PublicProps } from 'vue';
5
+
6
+ declare interface AuthConfig {
7
+ type: 'none' | 'Basic' | 'Bearer';
8
+ username?: string;
9
+ password?: string;
10
+ token?: string;
11
+ }
12
+
13
+ declare const _default: DefineComponent<Props, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {} & {
14
+ "update:modelValue": (value: RequestSchema) => any;
15
+ }, string, PublicProps, Readonly<Props> & Readonly<{
16
+ "onUpdate:modelValue"?: ((value: RequestSchema) => any) | undefined;
17
+ }>, {
18
+ modelValue: RequestSchema;
19
+ }, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLDivElement>;
20
+ export { _default as RequestForm }
21
+ export default _default;
22
+
23
+ export declare const defaultRequestSchema: RequestSchema;
24
+
25
+ export declare function executeRequest(schema: RequestSchema, method?: RequestMethod): Promise<ResponseData>;
26
+
27
+ export declare const KeyValueInput: DefineComponent<Props_2, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {} & {
28
+ "update:modelValue": (value: KeyValueItem[]) => any;
29
+ }, string, PublicProps, Readonly<Props_2> & Readonly<{
30
+ "onUpdate:modelValue"?: ((value: KeyValueItem[]) => any) | undefined;
31
+ }>, {
32
+ addButtonText: string;
33
+ showPreview: boolean;
34
+ previewText: string;
35
+ }, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLDivElement>;
36
+
37
+ declare interface KeyValueItem {
38
+ key: string;
39
+ value: string;
40
+ }
41
+
42
+ export declare interface KeyValuePair {
43
+ key: string;
44
+ value: string;
45
+ }
46
+
47
+ declare interface Props {
48
+ modelValue?: RequestSchema;
49
+ }
50
+
51
+ declare interface Props_2 {
52
+ modelValue: KeyValueItem[];
53
+ addButtonText?: string;
54
+ showPreview?: boolean;
55
+ previewText?: string;
56
+ }
57
+
58
+ declare interface RequestBody {
59
+ type: 'application/json' | 'multipart/form-data' | 'text/plain';
60
+ json?: string;
61
+ formData?: KeyValuePair[];
62
+ raw?: string;
63
+ }
64
+
65
+ declare type RequestMethod = 'fetch' | 'xhr';
66
+
67
+ export declare interface RequestSchema {
68
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'OPTIONS';
69
+ url: string;
70
+ path: string;
71
+ auth: AuthConfig;
72
+ params: KeyValuePair[];
73
+ headers: KeyValuePair[];
74
+ body: RequestBody;
75
+ }
76
+
77
+ export declare interface ResponseData {
78
+ status: string;
79
+ headers: Record<string, string>;
80
+ body: string;
81
+ timing?: number;
82
+ }
83
+
84
+ export { }