Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MobileAppDev Assignment 1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Siu Yee Pun
MobileAppDev Assignment 1
Commits
ff8c011f
Commit
ff8c011f
authored
4 months ago
by
Yuki
Browse files
Options
Downloads
Patches
Plain Diff
Task 2 part 2a: Get more data with `Uri.https`
parent
38003e32
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
assignment_1_base_project/lib/networking/api.dart
+23
-8
23 additions, 8 deletions
assignment_1_base_project/lib/networking/api.dart
with
23 additions
and
8 deletions
assignment_1_base_project/lib/networking/api.dart
+
23
−
8
View file @
ff8c011f
...
@@ -8,7 +8,7 @@ import 'package:assignment_1_base_project/db/character.dart';
...
@@ -8,7 +8,7 @@ import 'package:assignment_1_base_project/db/character.dart';
class
API
{
class
API
{
// Note: the documentation for the API can be found here: https://anapioficeandfire.com/Documentation
// Note: the documentation for the API can be found here: https://anapioficeandfire.com/Documentation
final
String
_charactersRoute
=
"https://anapioficeandfire.com/api/characters"
;
//
final String _charactersRoute = "https://anapioficeandfire.com/api/characters";
Map
<
String
,
dynamic
>
extractFields
(
Map
<
String
,
dynamic
>
json
)
{
Map
<
String
,
dynamic
>
extractFields
(
Map
<
String
,
dynamic
>
json
)
{
return
{
return
{
...
@@ -26,15 +26,28 @@ class API {
...
@@ -26,15 +26,28 @@ class API {
List
<
Character
>
_characters
=
[];
List
<
Character
>
_characters
=
[];
try
{
try
{
var
uri
=
Uri
.
parse
(
_charactersRoute
);
// var uri = Uri.parse(_charactersRoute);
var
uri
=
Uri
.
https
(
"anapioficeandfire.com"
,
// Authority domain
'/api/characters'
,
// Unencode Path
{
// Query Parameters
'pageSize'
:
'50'
,
// pageSize (Default : 10, Max : 50)
'page'
:
'1'
// page (Default: 1)
},
);
///// DEBUG /////
// print("//// DEBUG --- API START --- // _charactersRoute : ${_charactersRoute}");
var
response
=
await
http
.
get
(
uri
);
var
response
=
await
http
.
get
(
uri
);
// print("//// DEBUG // response.body.runtimeType:${response.body.runtimeType}"); // String
///// DEBUG /////
// print(//// DEBUG // response.body);
// // print("//// DEBUG // response.body.runtimeType: ${response.body.runtimeType}"); // String
// // print("//// DEBUG // ${response.body}");
if
(
response
.
statusCode
==
200
)
{
if
(
response
.
statusCode
==
200
)
{
final
jsonList
=
jsonDecode
(
response
.
body
);
final
jsonList
=
jsonDecode
(
response
.
body
);
// print("jsonList.runtimeType:${jsonList.runtimeType}"); // List<dynamic>
// print("
//// DEBUG //
jsonList.runtimeType:${jsonList.runtimeType}"); // List<dynamic>
//
print("//// DEBUG // jsonList.length:${jsonList.length}
"); // 10
print
(
"//// DEBUG // jsonList.length:
${jsonList.length}
record(s) got "
);
// Query records number
_characters
=
Character
.
listFromJson
(
jsonList
);
_characters
=
Character
.
listFromJson
(
jsonList
);
}
else
{
}
else
{
...
@@ -44,8 +57,10 @@ class API {
...
@@ -44,8 +57,10 @@ class API {
print
(
"Exceptions error: (
${e}
)"
);
print
(
"Exceptions error: (
${e}
)"
);
}
}
// print("//// DEBUG // _characters.length: ${_characters.length} - number of valid data");
///// DEBUG /////
// print("//// DEBUG // _characters:${_characters}");
// print("//// DEBUG --- API Result --- // _characters:${_characters}");
print
(
"//// DEBUG --- API Result --- // _characters.length:
${_characters.length}
- number of valid data saved"
);
// Query records number
return
_characters
;
return
_characters
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment