retrolite 1.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

retrolite #

retrolite is a RESTful API client for Dart and Flutter, with a simple API syntax, without reflection.

This package uses the abstraction classes from flutuate_api, used to create RESTful api clients.

Configuration #

Add retrolite to pubspec.yaml under the dependencies field.

dependencies:
  retrolite: ^latest_version

Import #

Add the following import in your library :

import 'package:retrolite/retrolite.dart';

Example #

Below, a simple provider sample to REQ|RES API:

/// [REQ|RES](https://reqres.in) API provider 
class ReqResApi extends IApi {
  /// Get the users list.
  Future<Response<ListUsers>> listUsers(int page) => 
    client.get<ListUsers>(
      'api/users?page=$page',
      contentType: ContentType.json,
      deserializer: ListUsers.deserialize,
    );

  /// Request the users list with delay.
  Future<Response<ListUsers>> listUsersWithDelay(int delay) => 
    client.get<ListUsers>(
      'api/users',
      queryParameters: {
        'delay': delay
      },
      contentType: ContentType.json,
      deserializer: ListUsers.deserialize,
    );

  /// Request the register service with success.
  Future<Response<RegisterResult>> register(RegisterContent content) => 
    client.post<RegisterResult>(
      'api/register',
      deserializer: RegisterResult.deserialize,
      contentType: ContentType.json,
      body: content
    );
}

Usage #

The sample project has more details about how to use the Retrolite package.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

1.1.2 #

  • Sources formatted

1.1.1 #

  • Sources formatted

1.1.0 #

  • Migrated package flutuate_api to here;
  • Implemented PUT, PATCH, HEAD, DELETE requests.

1.0.0 #

  • First release.

0.0.1 #

  • Initial version, created by Luciano Rodrigues

example/retrolite_example.dart

import 'dart:io';

import 'package:http/http.dart' as http;
import 'package:http/io_client.dart';
import 'package:retrolite/Secrets.dart';
import 'package:retrolite/flutuate_api.dart';
import 'package:retrolite/retrolite.dart';

import 'reqres/RegisterContent.dart';
import 'reqres/ReqResApi.dart';
import 'tmdb/TmdbApi.dart';

main() async {
  await listMoviesGenresFromTmdbApi();

  await registerFromReqResApi();
}

void listMoviesGenresFromTmdbApi() async {
  print('Calling TMDB api...\n');

  Retrolite retrolite = Retrolite(
    'https://api.themoviedb.org/3/',
    httpClientCreator: newHttpClient,
  );

  Secrets secrets = await Secrets.loadFromFile();

  if (secrets.containsKey('tmdb_token')) {
    TmdbApi api =
        retrolite.register<TmdbApi>(new TmdbApi(secrets['tmdb_token']));

    await api.genresForMovies().then((response) {
      for (var genre in response.body.genres) {
        print(genre.toJson());
      }
    });
  } else {
    print(
        'Please, specifies you TMDB API token in "resources/secrets.json" file.');
  }
  print('');
}

void registerFromReqResApi() async {
  print('Calling REQ|RES api...\n');

  Retrolite retrolite = Retrolite(
    'https://reqres.in',
    httpClientCreator: newUnsafeHttpClient,
  );

  ReqResApi api = retrolite.register<ReqResApi>(new ReqResApi());

  RegisterContent content = new RegisterContent('eve.holt@reqres.in', 'pistol');

  await api.register(content).then((response) {
    print(response.body.toJson());
  });
  print('');
}

/// Returns an instance of the default http client.
http.BaseClient newHttpClient() {
  return newDefaultHttpClient();
}

/// Returns an http client that ignores unsafe SSL certificates.
http.BaseClient newUnsafeHttpClient() {
  final bool trustSelfSigned = true;
  HttpClient httpClient = new HttpClient()
    ..badCertificateCallback =
        ((X509Certificate cert, String host, int port) => trustSelfSigned);
  return new IOClient(httpClient);
}

Use this package as a library

1. Depend on it

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


dependencies:
  retrolite: ^1.1.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:retrolite/retrolite.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
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]
50
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Format lib/Secrets.dart.

Run dartfmt to format lib/Secrets.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
collection ^1.14.11 1.14.12
http ^0.12.0+2 0.12.0+4
Transitive dependencies
async 2.4.1
charcode 1.1.3
http_parser 3.1.4
meta 1.1.8
path 1.6.4
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
pedantic ^1.0.0 1.9.0
test ^1.0.0