Flutter
[Flutter] Rest API (Dio)
전자기린
2022. 2. 15. 19:53
1. 패키지 참조 (pubspec.yaml)
dependencies:
dio: ^4.0.4
import 'package:dio/dio.dart';
Method - GET
TextButton(
onPressed: () async {
var result = await Dio().get(
"http://localhost:3000/organization",
queryParameters: {
"country": "Honduras"
});
print(result.data.toString());
},
child: const Text("GET")
),
Method - POST
TextButton(
onPressed: () async {
var result = await Dio().post(
"http://localhost:3000/admin/login-admin",
data: '{ "Id" : "admin", "Pw" : "admin"}');
print(result.data.toString());
},
child: const Text("POST")),
Method - PUT
TextButton(
onPressed: () async {
var result = await Dio().put(
"http://localhost:3000/admin/login-admin",
data: '{ "Id" : "admin", "Pw" : "admin"}');
print(result.data.toString());
},
child: const Text("PUT")),
Method - DELETE
TextButton(
onPressed: () async {
var result = await Dio().delete(
"http://localhost:3000/organization",
queryParameters: {
"category": "Other State",
});
print(result.data.toString());
},
child: const Text("DELETE")),