1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 13:58:47 +00:00
Files
samples/compass_app/server/lib/routes/destination.dart
2025-02-12 18:08:01 -05:00

37 lines
913 B
Dart

// Copyright 2024 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:convert';
import 'package:shelf/shelf.dart';
import 'package:shelf_router/shelf_router.dart';
import '../config/assets.dart';
class DestinationApi {
Router get router {
final router = Router();
router.get('/', (Request request) {
return Response.ok(
json.encode(Assets.destinations),
headers: {'Content-Type': 'application/json'},
);
});
router.get('/<id>/activity', (Request request, String id) {
final list =
Assets.activities
.where((activity) => activity.destinationRef == id)
.toList();
return Response.ok(
json.encode(list),
headers: {'Content-Type': 'application/json'},
);
});
return router;
}
}