GardenPlanner/lib/api/http_connection.dart

45 lines
1021 B
Dart
Raw Normal View History

2023-06-25 10:13:39 +02:00
import 'dart:convert';
import 'package:http/http.dart' as http;
import '../constance.dart';
//Not testet becase only wrap around http
class HttpConnector {
static final String _apiLocation = Constance.apiLocation;
Future<http.Response> getAllPlants() async {
final url = Uri.parse('$_apiLocation/plants');
final response = await http.get(url);
return response;
}
Future<http.Response> getPlant(int id) async {
final url = Uri.parse('$_apiLocation/plants/$id');
final response = await http.get(url);
return response;
}
Future<http.Response> getBeet() async {
final url = Uri.parse('$_apiLocation/beet');
final response = await http.get(url);
return response;
}
Future<http.Response> saveBeet(String body) async {
final url = Uri.parse('$_apiLocation/beet');
final headers = {'Content-Type': 'application/json'};
final response = await http.post(
url,
headers: headers,
body: utf8.encode(body),
);
return response;
}
}