cloudflare/cloudflare-typescript

Public

mirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0f711a6ec6dfa3a06bb7b4f9dcb2223ac65707d9

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/internal/request-options.ts

91lines · modecode

1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3import { NullableHeaders } from './headers';
4
5import type { BodyInit } from './builtin-types';
6import type { HTTPMethod, MergedRequestInit } from './types';
7import { type HeadersLike } from './headers';
8
9export type FinalRequestOptions = RequestOptions & { method: HTTPMethod; path: string };
10
11export type RequestOptions = {
12 /**
13 * The HTTP method for the request (e.g., 'get', 'post', 'put', 'delete').
14 */
15 method?: HTTPMethod;
16
17 /**
18 * The URL path for the request.
19 *
20 * @example "/v1/foo"
21 */
22 path?: string;
23
24 /**
25 * Query parameters to include in the request URL.
26 */
27 query?: object | undefined | null;
28
29 /**
30 * The request body. Can be a string, JSON object, FormData, or other supported types.
31 */
32 body?: unknown;
33
34 /**
35 * HTTP headers to include with the request. Can be a Headers object, plain object, or array of tuples.
36 */
37 headers?: HeadersLike;
38
39 /**
40 * The maximum number of times that the client will retry a request in case of a
41 * temporary failure, like a network error or a 5XX error from the server.
42 *
43 * @default 2
44 */
45 maxRetries?: number;
46
47 stream?: boolean | undefined;
48
49 /**
50 * The maximum amount of time (in milliseconds) that the client should wait for a response
51 * from the server before timing out a single request.
52 *
53 * @unit milliseconds
54 */
55 timeout?: number;
56
57 /**
58 * Additional `RequestInit` options to be passed to the underlying `fetch` call.
59 * These options will be merged with the client's default fetch options.
60 */
61 fetchOptions?: MergedRequestInit;
62
63 /**
64 * An AbortSignal that can be used to cancel the request.
65 */
66 signal?: AbortSignal | undefined | null;
67
68 /**
69 * A unique key for this request to enable idempotency.
70 */
71 idempotencyKey?: string;
72
73 /**
74 * Override the default base URL for this specific request.
75 */
76 defaultBaseURL?: string | undefined;
77
78 __binaryResponse?: boolean | undefined;
79};
80
81export type EncodedContent = { bodyHeaders: HeadersLike; body: BodyInit };
82export type RequestEncoder = (request: { headers: NullableHeaders; body: unknown }) => EncodedContent;
83
84export const FallbackEncoder: RequestEncoder = ({ headers, body }) => {
85 return {
86 bodyHeaders: {
87 'content-type': 'application/json',
88 },
89 body: JSON.stringify(body),
90 };
91};
92