Skip to main content

APIs

apis[name]​

ApiMethodProxy app.apis[String apiName]

Call API gateway interface. Supports accessing API proxy objects via subscript operator for chained calls. Supports GET, POST, PUT, DELETE, HEAD, OPTIONS, PATCH methods.

Parameters

apiName
String

API name

Response

ApiMethodProxy
ApiMethodProxy

API method proxy object, supports chained calls

ApiResponse
ApiResponse

API response

Example

// POST request
final result = await app.apis['myApi'].post(
path: '/users',
body: {'name': 'Zhang San', 'age': 25},
);

if (result.isSuccess) {
print('Response data: ${result.data}');
}

// GET request
final getResult = await app.apis['myApi'].get(path: '/users/123');

// PUT request
final putResult = await app.apis['myApi'].put(
path: '/users/123',
body: {'name': 'Li Si'},
);

// DELETE request
final deleteResult = await app.apis['myApi'].delete(path: '/users/123');

api​

ApiMethodProxy app.apis.api(String apiName)

Get an API proxy by name. Later calls work the same way as app.apis[apiName].

Parameters

apiName
String

API name

Response

ApiMethodProxy
ApiMethodProxy

API method proxy

Example

final myApi = app.apis.api('myApi');
final result = await myApi.get(path: '/users');

callApi​

Future<ApiResponse> app.apis.callApi(CallApiOptions options)

Call an API directly. A path that does not start with / is prefixed automatically. An unrecognized method is sent as POST.

Parameters

options
CallApiOptions

Call options

Response

Future
ApiResponse

API response

Example

final result = await app.apis.callApi(CallApiOptions(
name: 'myApi',
method: 'POST',
path: '/users',
body: {'name': 'test'},
));

gatewayOrigin​

String? app.apis.gatewayOrigin

Public field. Current requests do not read it, so assigning a value does not change the request URL.