jaguar_client 2.2.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 85

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

@Controller(path: '/api')
class ExampleApi {
  @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 = new Jaguar(port: 10123);
  server.add(reflect(new 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.2.1

2. Install it

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.

3. Import it

Now in your Dart code, you can use:


import 'package:jaguar_client/jaguar_client.dart';
  
Version Uploaded Documentation Archive
2.2.1 Aug 8, 2018 Go to the documentation of jaguar_client 2.2.1 Download jaguar_client 2.2.1 archive
2.1.10 Jul 26, 2018 Go to the documentation of jaguar_client 2.1.10 Download jaguar_client 2.1.10 archive
2.1.9 Jul 25, 2018 Go to the documentation of jaguar_client 2.1.9 Download jaguar_client 2.1.9 archive
2.1.8 Jul 11, 2018 Go to the documentation of jaguar_client 2.1.8 Download jaguar_client 2.1.8 archive
2.1.6 Jul 8, 2018 Go to the documentation of jaguar_client 2.1.6 Download jaguar_client 2.1.6 archive
2.1.5 Jul 8, 2018 Go to the documentation of jaguar_client 2.1.5 Download jaguar_client 2.1.5 archive
2.1.4 Jun 29, 2018 Go to the documentation of jaguar_client 2.1.4 Download jaguar_client 2.1.4 archive
2.1.3 Jun 28, 2018 Go to the documentation of jaguar_client 2.1.3 Download jaguar_client 2.1.3 archive
2.1.2 Jun 28, 2018 Go to the documentation of jaguar_client 2.1.2 Download jaguar_client 2.1.2 archive
2.1.1 Jun 28, 2018 Go to the documentation of jaguar_client 2.1.1 Download jaguar_client 2.1.1 archive

All 29 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
70
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
85
Learn more about scoring.

We analyzed this package on Aug 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.11.8

Platforms

Detected platforms: Flutter, other

Primary library: package:jaguar_client/jaguar_client.dart with components: io.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
async ^2.0.7 2.0.8
auth_header ^2.1.1 2.1.1
client_cookie ^2.1.2 2.1.5
http ^0.11.3 0.11.3+17
jaguar_resty ^2.6.1 2.6.2
jaguar_serializer ^2.2.0 2.2.0
Transitive dependencies
charcode 1.1.2
collection 1.14.11
http_parser 3.1.3
meta 1.1.6
path 1.6.2
source_span 1.4.1
string_scanner 1.0.4
typed_data 1.1.6
Dev dependencies
build_runner ^0.10.0
build_web_compilers ^0.4.0
jaguar ^2.1.37
jaguar_reflect ^2.1.4
jaguar_serializer_cli ^2.2.0
test ^1.3.0