Skip to content

Commit d85efde

Browse files
authored
Merge pull request #1405 from appwrite/feat/sdk-header-getters
Add header getters across generated SDKs
2 parents dbd264c + 051e8a9 commit d85efde

42 files changed

Lines changed: 221 additions & 9 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

example.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,22 @@ function configureSDK($sdk, $overrides = []) {
5656
'twitter' => 'appwrite',
5757
'discord' => ['564160730845151244', 'https://appwrite.io/discord'],
5858
'readme' => '**README**',
59+
'exclude' => [
60+
'services' => [
61+
['name' => 'documentsDB'],
62+
['name' => 'vectorsDB'],
63+
],
64+
],
5965
];
6066

67+
// Deep-merge exclude services so overrides add to defaults rather than replacing
68+
if (isset($overrides['exclude']['services']) && isset($defaults['exclude']['services'])) {
69+
$overrides['exclude']['services'] = array_merge(
70+
$defaults['exclude']['services'],
71+
$overrides['exclude']['services']
72+
);
73+
}
74+
6175
$config = array_merge($defaults, $overrides);
6276

6377
$sdk->setName($config['name'])
@@ -99,7 +113,7 @@ function configureSDK($sdk, $overrides = []) {
99113
// $platform = 'server';
100114
}
101115

102-
$version = '1.8.x';
116+
$version = '1.9.x';
103117
$speclessSDKs = ['agent-skills', 'cursor-plugin'];
104118
$needsSpec = !$requestedSdk || !in_array($requestedSdk, $speclessSDKs);
105119

templates/android/library/src/main/java/io/package/Client.kt.twig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,28 @@ class Client @JvmOverloads constructor(
219219
return this
220220
}
221221

222+
/**
223+
* Get the current request headers used for Appwrite API calls.
224+
*
225+
* @return a copy of the current request headers
226+
*/
227+
fun getHeaders(): Map<String, String> = headers.toMap()
228+
229+
/**
230+
* Get the cookies for a given URL from the SDK's cookie store.
231+
*
232+
* @param url the URL to retrieve cookies for
233+
* @return a list of cookies for the given URL
234+
*/
235+
fun getCookies(url: String): List<Cookie> = cookieJar.loadForRequest(url.toHttpUrl())
236+
237+
/**
238+
* Get the OkHttpClient instance used by this SDK.
239+
*
240+
* @return the OkHttpClient instance used by this client
241+
*/
242+
fun getHttpClient(): OkHttpClient = http
243+
222244
/**
223245
* Sends a "ping" request to Appwrite to verify connectivity.
224246
*

templates/apple/Sources/Client.swift.twig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ open class Client {
178178
return self
179179
}
180180

181+
open func getHeaders() -> [String: String] {
182+
return self.headers
183+
}
184+
181185
///
182186
/// Builds a query string from parameters
183187
///

templates/cli/lib/client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ class Client {
156156
return this;
157157
}
158158

159+
getHeaders(): Headers {
160+
return { ...this.headers };
161+
}
162+
159163
async call<T = unknown>(
160164
method: string,
161165
path: string = "",

templates/dart/lib/src/client.dart.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ abstract class Client {
4848
/// Add headers that should be sent with all API calls.
4949
Client addHeader(String key, String value);
5050

51+
/// Get the current request headers.
52+
Map<String, String> getHeaders();
53+
5154
/// Sends a "ping" request to Appwrite to verify connectivity.
5255
Future<String> ping();
5356

templates/dart/lib/src/client_base.dart.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ abstract class ClientBase implements Client {
2020
@override
2121
ClientBase addHeader(String key, String value);
2222

23+
@override
24+
Map<String, String> getHeaders();
25+
2326
@override
2427
Future<String> ping() async {
2528
final String apiPath = '/ping';

templates/dart/lib/src/client_browser.dart.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ class ClientBrowser extends ClientBase with ClientMixin {
8181
return this;
8282
}
8383

84+
@override
85+
Map<String, String> getHeaders() {
86+
return Map<String, String>.from(_headers!);
87+
}
88+
8489
@override
8590
Future<String?> webAuth(Uri url) async {
8691
final request = http.Request('GET', url);

templates/dart/lib/src/client_io.dart.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ class ClientIO extends ClientBase with ClientMixin {
9393
return this;
9494
}
9595

96+
@override
97+
Map<String, String> getHeaders() {
98+
return Map<String, String>.from(_headers!);
99+
}
100+
96101
@override
97102
Future<Response> chunkedUpload({
98103
required String path,

templates/deno/src/client.ts.twig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ export class Client {
6868
return this;
6969
}
7070

71+
getHeaders(): Payload {
72+
return { ...this.headers };
73+
}
74+
7175
async call(method: string, path: string = "", headers: Payload = {}, params: Payload = {}, responseType: string = "json") {
7276
headers = {...this.headers, ...headers};
7377
const url = new URL(this.endpoint + path);
@@ -156,4 +160,4 @@ export class Client {
156160

157161
return output;
158162
}
159-
}
163+
}

templates/dotnet/Package/Client.cs.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ namespace {{ spec.title | caseUcfirst }}
131131
return this;
132132
}
133133

134+
public Dictionary<string, string> GetHeaders()
135+
{
136+
return new Dictionary<string, string>(_headers);
137+
}
138+
134139
private HttpRequestMessage PrepareRequest(
135140
string method,
136141
string path,

0 commit comments

Comments
 (0)