http_resource 0.1.1
Http_Resource #
About #
This library is used to create easy bindings of your flutter/frontend dart application. By default if You have any data model, You can simply add HttpClient bindings and your model will be automatically binded to api endpoints.
Example #
import 'package:http_resource/http_resource.dart';
class Todo extends Model<Todo> {
HttpClient httpClient = TodoClient();
int userId;
String title;
String body;
bool completed;
Map<String, dynamic> get fields => {
'id': this.id,
'userId': userId,
'title': title,
'body': body,
'completed': completed
};
@override
Map<String, dynamic> setFields() => {
"id": (value) => this.id = value,
"userId": (value) => userId = value,
"title": (value) => title = value,
"body": (value) => body = value,
"completed": (value) => completed = value,
};
}
class TodoClient extends HttpClient<Todo> {
@override
String get apiUrl => 'https://jsonplaceholder.typicode.com/todos';
@override
Todo getInstance() {
return Todo();
}
}
void main() async {
List<Todo> todo = await TodoClient().all();
Todo test = await TodoClient().first(1);
Todo create = Todo();
create.userId = 1;
create.title = 'testtitle';
await create.create();
create.id = 1;
create.body = "trele body";
await create.update();
}
Info #
This package was made for my own needs, but since I'm repeating this step very often, I've decided to push this as public package. Maybe someone will need this too. Any proposals are welcomed.
import 'package:http_resource/http_resource.dart';
class Todo extends Model<Todo> {
HttpClient httpClient = TodoClient();
int userId;
String title;
String body;
bool completed;
Map<String, dynamic> get fields => {
'id': this.id,
'userId': userId,
'title': title,
'body': body,
'completed': completed
};
@override
Map<String, dynamic> setFields() => {
"id": (value) => this.id = value,
"userId": (value) => userId = value,
"title": (value) => title = value,
"body": (value) => body = value,
"completed": (value) => completed = value,
};
}
class TodoClient extends HttpClient<Todo> {
@override
String get apiUrl => 'https://jsonplaceholder.typicode.com/todos';
@override
Todo getInstance() {
return Todo();
}
}
void main() async {
List<Todo> todo = await TodoClient().all();
Todo test = await TodoClient().first(1);
Todo create = Todo();
create.userId = 1;
create.title = 'testtitle';
await create.create();
create.id = 1;
create.body = "trele body";
await create.update();
}
Use this package as a library
1. Depend on it
Add this to your package's pubspec.yaml file:
dependencies:
http_resource: ^0.1.1
2. Install it
You can install packages from the command line:
with pub:
$ pub get
with Flutter:
$ flutter pub get
Alternatively, your editor might support pub get
or flutter pub get
.
Check the docs for your editor to learn more.
3. Import it
Now in your Dart code, you can use:
import 'package:http_resource/http_resource.dart';
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
0
|
Health:
Code health derived from static analysis.
[more]
|
99
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
80
|
Overall:
Weighted score of the above.
[more]
|
46
|
We analyzed this package on Nov 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
- Dart: 2.6.1
- pana: 0.12.21
Platforms
Detected platforms: Flutter, web, other
No platform restriction found in primary library
package:http_resource/http_resource.dart
.
Health issues and suggestions
Document public APIs. (-1 points)
27 out of 27 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.
Format lib/http_resource.dart
.
Run dartfmt
to format lib/http_resource.dart
.
Maintenance issues and suggestions
Provide a file named CHANGELOG.md
. (-20 points)
Changelog entries help developers follow the progress of your package. See the example generated by stagehand
.
Dependencies
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=2.1.0 <3.0.0 | ||
http | ^0.12.0 | 0.12.0+2 | |
Transitive dependencies | |||
async | 2.4.0 | ||
charcode | 1.1.2 | ||
collection | 1.14.12 | ||
http_parser | 3.1.3 | ||
meta | 1.1.8 | ||
path | 1.6.4 | ||
pedantic | 1.8.0+1 | ||
source_span | 1.5.5 | ||
string_scanner | 1.0.5 | ||
term_glyph | 1.1.0 | ||
typed_data | 1.1.6 |