jaguar_resty 2.10.12

jaguar_resty #

Build fluent functional Restful clients

Features #

  • Fluent API to set:
    • Hierarchical paths
      • get('http://localhost:8080', '/api/book/${id}').go()
      • get('api').path('book').path(id).go()
    • Query parameters
      • get('/books').query('page', '2').list()
    • Headers
      • get('/book').header('page', '2').list()
    • Body
      • post('/book').json(Book('1', 'Harry potter')).one()
  • JSON request encoding
    • post('/book').json(Book('1', 'Harry potter')).one()
  • JSON request decoding
    • get('/book/1').one(Book.map)
  • URL encoded forms
  • Multipart form
  • Cookie jar
    • get('/data').interceptBefore(jar.intercept).go()
  • Interceptors
    • get('/data').interceptBefore(jar.intercept).go()
  • Authenticators

Changelog #

2.10.12 #

  • StringResponse.cookies

2.10.10 #

  • Fixed throw on failure buf in go

2.10.9 #

  • Response's toString now prints clear debug message
  • Bug fix in go method's handling of after's result

2.10.4 #

  • Added map method to Response

2.8.8 #

  • Added RouteWithBody and getBody

2.8.5 #

  • OnSuccess, onFailure, run and isFailure for Response
  • onSuccess and onFailure for go

Breaking change #

  • then positional argument is converted to named parameter in go

2.8.4 #

  • Added Patch

2.8.1-dev.2 #

  • Powerful After interceptor

2.8.1-dev.1 #

  • Class based Interceptor

2.8.1-dev.0 #

  • Fixed query bug when data is not string
  • Standardised setters in request creators

2.6.2 #

  • Dart 2 stable

2.5.16 #

  • Fixed query copying bug

2.5.15 #

  • Added BearerToken interceptor

2.5.12 #

  • pub fixes

2.5.9 #

  • Fixed bugs in go method

2.5.6 #

  • Dart2 bug fixes

2.5.4 #

  • Dart 2 bug fix

2.5.4 #

  • Dart 2 bug fixes

2.5.2 #

  • Casting bug fixes

2.5.1 #

  • Unified authority and path setter in constructors
  • Added setUrl method

2.4.2 #

  • Exposed parseMimeType and parseEncoding

2.4.1 #

  • Simpler one, List, decode and decodeList methods

2.3.6 #

  • Success hooks on Response

2.3.5 #

  • Success hooks

2.3.4 #

  • Support for authorization headers

2.3.3 #

  • Exposed headerMap and queryMap

2.3.2 #

  • Added urlEncodedForm to Put

2.3.1 #

  • Renamed authority to origin

2.2.2 #

  • Added options convenience function

2.2.1 #

  • go gets an optional then callback
  • Added OptionsMethod

2.1.3 #

  • Bug fixes

2.1.2 #

  • CookieJar's interceptor method renamed to intercept

2.1.1 #

  • Renamed fetchResponse to go
  • Renamed fetch to one
  • Renamed fetchList to List

1.1.3 #

  • authority bug fix

1.1.2 #

  • Multipart forms
  • Simultaneous authority and path definition

example/example.dart

import 'dart:async';
import 'package:http/io_client.dart' as ht;
import 'package:jaguar_resty/jaguar_resty.dart' as resty;
import 'package:jaguar/jaguar.dart';

class Book {
  String id;

  String name;

  Book({this.id, this.name});

  static Book map(Map map) => new Book()..fromMap(map);

  Map toJson() => {
        'id': id,
        'name': name,
      };

  void fromMap(Map map) => this
    ..id = map['id']
    ..name = map['name'];

  String toString() => toJson().toString();
}

final books = <Book>[
  new Book(id: '1', name: 'Harry potter'),
  new Book(id: '2', name: 'Da Vinci code'),
  new Book(id: '3', name: 'Angels and deamons'),
];

final server = new Jaguar(port: 8000)
  ..getJson(
      '/book/:id',
      (Context ctx) => books.firstWhere((b) => b.id == ctx.pathParams['id'],
          orElse: () => null))
  ..postJson('/book', (Context ctx) async {
    books.add(await ctx.bodyAsJson(convert: Book.map));
    return books;
  });

Future client() async {
  print(
      await resty.get('/book/1').http('localhost:8000').one(convert: Book.map));
  print(await resty
      .post('/book')
      .http('localhost:8000')
      .json(new Book(id: '4', name: 'Book4'))
      .list(convert: Book.map));
}

main() async {
  resty.globalClient = new ht.IOClient();

  await server.serve(logRequests: true);

  await client();
  await server.close();
}

Use this package as a library

1. Depend on it

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


dependencies:
  jaguar_resty: ^2.10.12

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

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

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:jaguar_resty/jaguar_resty.dart.

Health suggestions

Fix lib/routes/routes.dart. (-8.63 points)

Analysis of lib/routes/routes.dart reported 18 hints, including:

line 217 col 9: Use isEmpty instead of length

line 285 col 7: Use isNotEmpty instead of length

line 286 col 5: DO use curly braces for all flow control structures.

line 310 col 7: DO use curly braces for all flow control structures.

line 324 col 7: DO use curly braces for all flow control structures.

Fix lib/expect/expect.dart. (-3.93 points)

Analysis of lib/expect/expect.dart reported 8 hints, including:

line 59 col 9: DO use curly braces for all flow control structures.

line 72 col 9: DO use curly braces for all flow control structures.

line 82 col 9: DO use curly braces for all flow control structures.

line 88 col 11: DO use curly braces for all flow control structures.

line 103 col 9: DO use curly braces for all flow control structures.

Fix lib/response/response.dart. (-3.45 points)

Analysis of lib/response/response.dart reported 7 hints, including:

line 124 col 36: This function has a return type of 'FutureOr<Response

line 372 col 9: Use isNotEmpty instead of length

line 494 col 7: DO use curly braces for all flow control structures.

line 496 col 7: DO use curly braces for all flow control structures.

line 518 col 7: DO use curly braces for all flow control structures.

Fix lib/interceptor/interceptors.dart. (-0.50 points)

Analysis of lib/interceptor/interceptors.dart reported 1 hint:

line 45 col 7: DO use curly braces for all flow control structures.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
async ^2.0.6 2.3.0
auth_header ^2.1.2 2.1.4
client_cookie ^2.2.1 2.2.1
collection ^1.14.6 1.14.11
http ^0.12.0 0.12.0+2
http_parser ^3.1.1 3.1.3
meta ^1.1.6 1.1.7
path ^1.6.2 1.6.2
Transitive dependencies
charcode 1.1.2
pedantic 1.8.0+1
source_span 1.5.5
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
jaguar ^2.4.1
test ^1.3.0

Admin