jaguar_client 2.4.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 59

jaguar_client #

Concise JSON client library for Dart and Jaguar based on package:http

  • Built-in PODO serialization using jaguar_serializer
  • Simple and intuitive API
  • Various authentication support
    • JSON authentication
    • url-encoded-form authentication
    • Basic authentication
    • Planned
      • Facebook oauth
      • Google oauth
      • Google 2FA
  • Session management
    • Browser: LocalStorage
    • Flutter: SharedPreferences
    • IO: DB, File
  • JWT authentication support
  • ResourceClient to access DataStore or a resource
  • SerializedJsonClient enables writing concise REST calls
  • Persistent Cookies on Flutter and IO

Usage #

Basic requests #

GET 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);

Automatic serialization #

TODO

Authentication #

TODO

Session management #

TODO

TODO #

-[ ] Persist cookie
-[ ] Persist auth header?

Changelog #

2.1.8 #

  • Bug fixes

2.1.1 #

  • Uses jaguar_serializer 2.1.x

2.0.8 #

  • Casting bug fixes

2.0.5 #

  • resty 2.5.1

2.0.4 #

  • Query parameters bug fix

2.0.2 #

  • Uses jaguar_resty under the hood

0.1.5 #

  • Moved to jaguar_serializer 0.4.x

0.1.4 #

  • Matchers for testing

0.1.2 #

  • Fix in bug capturing Bearer auth header

0.1.1 #

  • Bearer auth header
  • Logout

example/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);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  jaguar_client: ^2.4.2

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:jaguar_client/jaguar_client.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
44
Health:
Code health derived from static analysis. [more]
77
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
67
Overall:
Weighted score of the above. [more]
59
Learn more about scoring.

We analyzed this package on Dec 12, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.1+4

Health suggestions

Fix lib/src/client.dart. (-22.17 points)

Analysis of lib/src/client.dart reported 50 hints, including:

line 17 col 31: Unnecessary new keyword.

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 53 col 12: Unnecessary new keyword.

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'.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (http).

Package is getting outdated. (-23.29 points)

The package was last published 64 weeks ago.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.65 <3.0.0
async ^2.0.7 2.4.0
auth_header ^2.1.1 2.1.4
client_cookie ^2.1.2 2.1.5 2.2.1
http ^0.11.3 0.11.3+17 0.12.0+2
jaguar_resty ^2.8.5 2.8.9 2.10.14
jaguar_serializer ^2.2.0 2.2.12
meta ^1.1.6 1.1.8
Transitive dependencies
charcode 1.1.2
collection 1.14.12
http_parser 3.1.3
path 1.6.4
source_span 1.5.5
string_scanner 1.0.5
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