createFeed method

Future<Feed> createFeed({
  1. required String projectId,
  2. required String name,
  3. String description = '',
  4. String visibility = 'private',
  5. bool paused = false,
  6. Map<String, String> annotations = const {},
  7. Object? messageSchema,
})

Implementation

Future<Feed> createFeed({
  required String projectId,
  required String name,
  String description = '',
  String visibility = 'private',
  bool paused = false,
  Map<String, String> annotations = const {},
  Object? messageSchema,
}) async {
  final encodedProjectId = Uri.encodeComponent(projectId);
  final uri = Uri.parse('$baseUrl/accounts/projects/$encodedProjectId/feeds');
  final body = {
    'name': name,
    'description': description,
    'visibility': visibility,
    'paused': paused,
    'annotations': annotations,
    'message_schema': messageSchema,
  };

  final response = await httpClient.post(uri, body: jsonEncode(body));
  if (response.statusCode >= 400) {
    throw MeshagentException(
      'Failed to create feed. '
      'Status code: ${response.statusCode}, body: ${response.body}',
    );
  }

  final data = jsonDecode(response.body) as Map<String, dynamic>;
  return Feed.fromJson(data['feed'] as Map<String, dynamic>);
}