-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathapi_service.dart
More file actions
54 lines (49 loc) · 1.35 KB
/
Copy pathapi_service.dart
File metadata and controls
54 lines (49 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import 'package:flutter_crud_api_sample_app/src/model/profile.dart';
import 'package:http/http.dart' show Client;
class ApiService {
final String baseUrl = "http://api.bengkelrobot.net:8001";
Client client = Client();
Future<List<Profile>> getProfiles() async {
final response = await client.get("$baseUrl/api/profile");
if (response.statusCode == 200) {
return profileFromJson(response.body);
} else {
return null;
}
}
Future<bool> createProfile(Profile data) async {
final response = await client.post(
"$baseUrl/api/profile",
headers: {"content-type": "application/json"},
body: profileToJson(data),
);
if (response.statusCode == 201) {
return true;
} else {
return false;
}
}
Future<bool> updateProfile(Profile data) async {
final response = await client.put(
"$baseUrl/api/profile/${data.id}",
headers: {"content-type": "application/json"},
body: profileToJson(data),
);
if (response.statusCode == 200) {
return true;
} else {
return false;
}
}
Future<bool> deleteProfile(int id) async {
final response = await client.delete(
"$baseUrl/api/profile/$id",
headers: {"content-type": "application/json"},
);
if (response.statusCode == 200) {
return true;
} else {
return false;
}
}
}