MCPcopy Index your code
hub / github.com/appwrite/sdk-for-react-native / call

Method call

src/client.ts:497–585  ·  view source on GitHub ↗
(method: string, url: URL, headers: Headers = {}, params: Payload = {}, responseType = 'json')

Source from the content-addressed store, hash-verified

495 }
496
497 async call(method: string, url: URL, headers: Headers = {}, params: Payload = {}, responseType = 'json'): Promise<any> {
498 method = method.toUpperCase();
499
500 headers = Object.assign({}, this.headers, headers);
501 headers.Origin = `appwrite-${Platform.OS}://${this.config.platform}`
502
503 let options: RequestInit = {
504 method,
505 headers,
506 };
507
508 if (headers['X-Appwrite-Dev-Key'] === undefined) {
509 options.credentials = 'include';
510 }
511
512 if (method === 'GET') {
513 for (const [key, value] of Object.entries(Service.flatten(params))) {
514 url.searchParams.append(key, value);
515 }
516 } else {
517 switch (headers['content-type']) {
518 case 'application/json':
519 options.body = JSONbig.stringify(params);
520 break;
521
522 case 'multipart/form-data':
523 let formData = new FormData();
524
525 for (const key in params) {
526 if (Array.isArray(params[key])) {
527 params[key].forEach((value: any) => {
528 formData.append(key + '[]', value);
529 })
530 } else {
531 formData.append(key, params[key]);
532 }
533 }
534
535 options.body = formData;
536 delete headers['content-type'];
537 break;
538 }
539 }
540
541 try {
542 let data = null;
543
544 const response = await fetch(url.toString(), options);
545
546 const warnings = response.headers.get('x-appwrite-warning');
547 if (warnings) {
548 warnings.split(';').forEach((warning: string) => console.warn('Warning: ' + warning));
549 }
550
551 if (response.headers.get('content-type')?.includes('application/json')) {
552 data = JSONbig.parse(await response.text());
553 } else if (responseType === 'arrayBuffer') {
554 data = await response.arrayBuffer();

Callers 15

listExecutionsMethod · 0.80
createExecutionMethod · 0.80
getExecutionMethod · 0.80
listFilesMethod · 0.80
createFileMethod · 0.80
getFileMethod · 0.80
updateFileMethod · 0.80
deleteFileMethod · 0.80
getFileDownloadMethod · 0.80
getFilePreviewMethod · 0.80
getFileViewMethod · 0.80
listMethod · 0.80

Calls 3

flattenMethod · 0.80
toStringMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected