index method
Provides an asynchronous method for rendering the index page of the controller.
This method returns an empty string by default. Subclasses should override this method to provide specific functionality for rendering the index view.
Returns a Future<String> that resolves to an empty string.
Implementation
@override
Future<String> index() async {
final payload = rq.getAll().removeAll(['POST', 'GET', 'FILE']);
try {
final JSONRPCRequest rpcRequest = JSONRPCRequest.toMCP(payload);
final stream = Stream.fromFuture(Future(() async {
final response = await _dispatch(
rpcRequest.method,
rpcRequest.id,
payload,
);
return SSE(data: FinchJson.jsonEncoder(response.toMap()));
}));
return await rq.renderSSE(stream);
} catch (e) {
final errorResponse = JSONRPCErrorResponse(
id: payload['id']?.toString() ?? '-1',
error: Error(code: -32600, message: 'Invalid Request: $e'),
);
final stream = Stream.fromIterable([
SSE(
data: FinchJson.jsonEncoder(errorResponse.toMap()),
),
]);
return await rq.renderSSE(stream, status: 400);
}
}