Skip to content

Instantly share code, notes, and snippets.

@nhancv
Created December 12, 2018 15:48
Show Gist options
  • Select an option

  • Save nhancv/2eeba0546788927a762a8337de28265e to your computer and use it in GitHub Desktop.

Select an option

Save nhancv/2eeba0546788927a762a8337de28265e to your computer and use it in GitHub Desktop.
Flutter api using http
import 'package:http/http.dart' as http;
import 'package:bflutter_poc/global.dart';
class Api {
static final Api _instance = Api._private();
Api._private();
factory Api() => _instance;
final String apiBaseUrl = Global().env.apiBaseUrl;
Future<http.Response> searchUsers(String query) {
String url = '$apiBaseUrl/search/users?q=$query';
return http.get(url);
}
Future<http.Response> getUserInfo(String username) {
return http.get('$apiBaseUrl/users/$username');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment