You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can specify a single HTTP method or an array of methods for an endpoint.
164
+
165
+
```ts
166
+
// Single method
167
+
const getItem =createEndpoint("/item", {
168
+
method: "GET",
169
+
}, async (ctx) => {
170
+
return { item: "data" }
171
+
})
172
+
173
+
// Multiple methods
174
+
const itemEndpoint =createEndpoint("/item", {
175
+
method: ["GET", "POST"],
176
+
}, async (ctx) => {
177
+
if (ctx.method==="POST") {
178
+
// handle POST - create/update
179
+
return { created: true }
180
+
}
181
+
// handle GET - read only
182
+
return { item: "data" }
183
+
})
184
+
```
185
+
186
+
When calling an endpoint with multiple methods directly (not through HTTP), the `method` parameter is **optional** and defaults to the **first method** in the array:
187
+
188
+
```ts
189
+
// Defaults to "GET" (first in array)
190
+
const result =awaititemEndpoint({ headers })
191
+
192
+
// Explicitly specify POST
193
+
const result =awaititemEndpoint({ headers, method: "POST" })
194
+
```
195
+
161
196
#### Media types
162
197
163
198
By default, all media types are accepted, but only a handful of them have a built-in support:
0 commit comments