22. Flutter - Http Package

Uses http to get data from third party online APIs.

Install http package from: https://pub.dev/packages/http

Edit pubspec.yaml file and import into a dart file.


Getting data from an endpoint or place:

get('ENDPOINT');


Using get inside a async function for effectiveness:

function() async {

Response response = get(Uri.http('ENDPOINT'));

// EXAMPLE 

Response response = await get(Uri.http("jsonplaceholder.typicode.com","todos/1"));

print(response.body);

}

// response type will make the variable whatever the get function gets from the endpoint and wraps in inside a body.

// must separate sub domains from the url using a comma.


Using built in convert package to decode json string:

import 'dart:convert';


function() async {

    Response response = get('ENDPOINT');

    Map mapexample = jsonDecode(response.body);

}


// json strings will be converted to a map to use in dart.



Comments

Popular posts from this blog

2. FreeCodeCamp - Dynamic Programming - Learn to Solve Algorithmic Problems & Coding Challenges

20. Data Analytics - Analyze Data to Answer Questions - Week 1

3. Algorithms - Selection Sort