Concise JSON client library for Dart and Jaguar based on package:http
jaguar_serializer
ResourceClient
to access DataStore
or a resourceSerializedJsonClient
enables writing concise REST callsGET request:
final JsonResponse resp =
await client.get('http://localhost:8080/api/list');
print(resp.body);
POST request:
final JsonResponse resp = await client
.post('http://localhost:8080/api/map', body: {'posting': 'hello'});
print(resp.body);
TODO
TODO
TODO
-[ ] Persist cookie
-[ ] Persist auth header?
jaguar_resty
under the hoodexample/example.dart
// Copyright (c) 2017, teja. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.
import 'dart:io';
import 'dart:async';
import 'package:http/http.dart' as http;
import 'package:jaguar/jaguar.dart';
import 'package:jaguar_client/jaguar_client.dart';
import 'package:jaguar_reflect/jaguar_reflect.dart';
import 'package:jaguar_serializer/jaguar_serializer.dart';
@GenController(path: '/api')
class ExampleApi extends Controller {
@GetJson(path: '/map')
Map getMap(_) => {'jaguar': 'awesome'};
@GetJson(path: '/list')
List<String> getList(_) => ['Hello', 'World'];
@GetJson(path: '/string')
String getString(_) => "Jaguar";
@GetJson(path: '/header')
Map<String, String> getHeader(Context ctx) =>
{'testing': ctx.req.headers.value('jaguar-testing')};
@PostJson(path: '/map')
Future<Map> postMap(Context ctx) => ctx.bodyAsJsonMap();
@PutJson(path: '/map')
Future<Map> putMap(Context ctx) => ctx.bodyAsJsonMap();
@DeleteJson(path: '/map/:id')
Map deleteMap(Context ctx) =>
{'id': ctx.pathParams['id'], 'query': ctx.query['query']};
@GetJson(path: '/bool')
bool get(Context ctx) => false;
}
Future serve() async {
Jaguar server = Jaguar(port: 10123);
server.add(reflect(ExampleApi()));
await server.serve();
}
Future client() async {
final http.Client baseClient = new http.Client();
final JsonClient client = new JsonClient(baseClient, repo: new JsonRepo());
{
final JsonResponse resp =
await client.get('http://localhost:10123/api/map');
print(resp.body);
}
{
final JsonResponse resp =
await client.get('http://localhost:10123/api/list');
print(resp.body);
}
{
final JsonResponse resp =
await client.get('http://localhost:10123/api/string');
print(resp.body);
}
{
final JsonResponse resp = await client.get(
'http://localhost:10123/api/header',
headers: {'jaguar-testing': 'testing 1 2 3'});
print(resp.body);
}
{
final JsonResponse resp = await client
.post('http://localhost:10123/api/map', body: {'posting': 'hello'});
print(resp.body);
}
{
final JsonResponse resp = await client
.put('http://localhost:10123/api/map', body: {'putting': 'hello'});
print(resp.body);
}
{
final JsonResponse resp =
await client.delete('http://localhost:10123/api/map/123?query=why');
print(resp.body);
}
{
final JsonResponse resp =
await client.get('http://localhost:10123/api/bool');
print(resp.decode<bool>());
}
}
main() async {
await serve();
await client();
exit(0);
}
Add this to your package's pubspec.yaml file:
dependencies:
jaguar_client: ^2.4.2
You can install packages from the command line:
with pub:
$ pub get
with Flutter:
$ flutter packages get
Alternatively, your editor might support pub get
or flutter packages get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:jaguar_client/jaguar_client.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
2.4.2 | Sep 18, 2018 |
|
|
2.4.1 | Sep 18, 2018 |
|
|
2.2.2 | Aug 24, 2018 |
|
|
2.2.1 | Aug 8, 2018 |
|
|
2.1.10 | Jul 26, 2018 |
|
|
2.1.9 | Jul 25, 2018 |
|
|
2.1.8 | Jul 11, 2018 |
|
|
2.1.6 | Jul 8, 2018 |
|
|
2.1.5 | Jul 8, 2018 |
|
|
2.1.4 | Jun 29, 2018 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
56
|
Health:
Code health derived from static analysis.
[more]
|
86
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
100
|
Overall:
Weighted score of the above.
[more]
|
74
|
We analyzed this package on Feb 14, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter, other
Primary library:
package:jaguar_client/jaguar_client.dart
with components:io
.
Fix lib/src/client.dart
. (-13.53 points)
Analysis of lib/src/client.dart
reported 29 hints, including:
line 19 col 56: Use =
to separate a named parameter from its default value.
line 43 col 32: Use =
to separate a named parameter from its default value.
line 44 col 30: Use =
to separate a named parameter from its default value.
line 60 col 32: Use =
to separate a named parameter from its default value.
line 61 col 30: Use =
to separate a named parameter from its default value.
Fix lib/src/src.dart
. (-0.50 points)
Analysis of lib/src/src.dart
reported 1 hint:
line 7 col 8: Unused import: 'package:async/async.dart'.
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=2.0.0-dev.65 <3.0.0 | ||
async | ^2.0.7 | 2.0.8 | |
auth_header | ^2.1.1 | 2.1.2 | |
client_cookie | ^2.1.2 | 2.1.5 | 2.2.1 |
http | ^0.11.3 | 0.11.3+17 | 0.12.0+1 |
jaguar_resty | ^2.8.5 | 2.8.9 | 2.10.12 |
jaguar_serializer | ^2.2.0 | 2.2.8 | |
meta | ^1.1.6 | 1.1.7 | |
Transitive dependencies | |||
charcode | 1.1.2 | ||
collection | 1.14.11 | ||
http_parser | 3.1.3 | ||
path | 1.6.2 | ||
source_span | 1.5.4 | ||
string_scanner | 1.0.4 | ||
term_glyph | 1.1.0 | ||
typed_data | 1.1.6 | ||
Dev dependencies | |||
build_runner | ^0.10.0 | ||
build_web_compilers | ^0.4.0 | ||
jaguar | ^2.4.1 | ||
jaguar_reflect | ^2.4.1 | ||
jaguar_serializer_cli | ^2.2.0 | ||
test | ^1.3.0 |