...

/

Solution: Crypto API

Solution: Crypto API

Explore solutions to the Crypto API challenge.

Solutions

Great job on completing all the steps in the previous challenge! Feel free to compare your code solutions with the solutions below:

import 'dart:convert';
import 'package:http/http.dart';
class CoinsService{
static final CoinsService _singleton = CoinsService._internal();
CoinsService._internal();
static CoinsService get instance => _singleton;
final _baseURL = 'https://44a3d77f-08c1-4a76-8073-52e7d46c888b.mock.pstmn.io/';
Future<List<dynamic>> getCoins()async{
const coinsEndpoint = '/coins/markets';
Response res = await get(Uri.parse(_baseURL + coinsEndpoint));
if (res.statusCode == 200) {
var body = jsonDecode(res.body);
return body;
} else {
throw "Unable to retrieve coins";
}
}
}
Crypto API solution code

Challenge 1: Get

...