Created
March 7, 2020 18:47
-
-
Save ishaquehassan/5b0578f98478f8de70ea0221c2e744bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:http/http.dart' as http; | |
class Api{ | |
static final String BASE_URL = "http://yourserver.com"; | |
static final String API_KEY = "YOUR_KEY"; | |
static String fcmTOKEN = "YOUR_TOKEN"; | |
Future<http.Response> getRequest(String endPoint){ | |
return http.get(BASE_URL+"/"+endPoint, headers: { | |
"apikey": API_KEY | |
}); | |
} | |
Future<http.Response> postRequest(String endPoint,Map<String,String> data){ | |
return http.post(BASE_URL+"/"+endPoint, headers: { | |
"apikey": API_KEY, | |
"Content-Type" : "application/x-www-form-urlencoded" | |
},body: data); | |
} | |
Future<http.Response> putRequest(String endPoint,Map<String,String> data){ | |
return http.put(BASE_URL+"/"+endPoint, headers: { | |
"apikey": API_KEY, | |
"Content-Type" : "application/x-www-form-urlencoded" | |
},body: data); | |
} | |
Future<http.StreamedResponse> deleteRequest(String endPoint,Map<String,String> data){ | |
var rq = http.Request('DELETE', Uri.parse(BASE_URL+"/"+endPoint)) | |
..headers.addAll({ | |
"apikey": API_KEY, | |
"Content-Type" : "application/x-www-form-urlencoded" | |
}); | |
rq.bodyFields = data; | |
return http.Client().send(rq); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment