Skip to content

Instantly share code, notes, and snippets.

@sergiandreplace
Created October 3, 2017 11:13
Show Gist options
  • Save sergiandreplace/c45814964ab6607f049a40ff7c276fb6 to your computer and use it in GitHub Desktop.
Save sergiandreplace/c45814964ab6607f049a40ff7c276fb6 to your computer and use it in GitHub Desktop.
Api request on dart
import 'dart:async';
import 'dart:convert';
import 'package:flutter/services.dart';
class SWApi {
Future<Map<String, String>> getCharacter(String id) async {
var httpClient = createHttpClient();
var response = await httpClient.get('https://swapi.co/api/people/${id}/');
Map<String, Object> character = JSON.decode(response.body);
print(character);
return character;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment