MCPcopy Create free account
hub / github.com/CapSoftware/Cap / publicRequest

Function publicRequest

apps/mobile/src/api/mobile.ts:149–176  ·  view source on GitHub ↗
(
		path: string,
		schema: Schema.Schema<A, I, never>,
		options: Omit<RequestOptions, "query"> = {},
	)

Source from the content-addressed store, hash-verified

147 };
148
149 const publicRequest = async <A, I>(
150 path: string,
151 schema: Schema.Schema<A, I, never>,
152 options: Omit<RequestOptions, "query"> = {},
153 ): Promise<A> => {
154 const url = new URL(path, origin);
155 const headers = new Headers();
156 let body: BodyInit | undefined;
157 if (options.body !== undefined) {
158 headers.set("Content-Type", "application/json");
159 body = JSON.stringify(options.body);
160 }
161
162 const response = await fetch(url.toString(), {
163 method: options.method ?? "GET",
164 headers,
165 body,
166 });
167 const payload = await parseJson(response);
168 if (!response.ok) {
169 throw new MobileApiError(
170 `Mobile API request failed with ${response.status}`,
171 response.status,
172 payload,
173 );
174 }
175 return decode(schema, payload);
176 };
177
178 return {
179 getAuthConfig: () =>

Callers 1

createMobileApiClientFunction · 0.85

Calls 3

parseJsonFunction · 0.85
decodeFunction · 0.85
fetchFunction · 0.50

Tested by

no test coverage detected