jaguar_http 0.0.2

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

jaguar_http

An Http Api generator inspired by Retrofit for Dart

Install

pub global activate jaguar_http_cli

Usage

A simple usage example:

pubspec.yaml

jaguar_http:
  - example/example.dart

example.yaml

library example;

part 'example.g.dart';

/// definition
@JaguarHttp(name: "Api")
abstract class ApiDefinition extends JaguarInterceptors {
  @Get("/users/:id")
  Future<JaguarResponse<User>> getUserById(@Param() String id);

  @Post("/users")
  Future<JaguarResponse<User>> postUser(@Body() User user);

  @Put("/users/:uid")
  Future<JaguarResponse<User>> updateUser(@Param(name: "uid") String userId, @Body() User user);

  @Delete("/users/:id")
  Future<JaguarResponse> deleteUser(@Param() String id);
}

run

jaguar_http build

use it

final api = new Api(new IOClient(), "http://localhost:9000", serializers: repo);

Features and bugs

Please file feature requests and bugs at the issue tracker.

Changelog

0.0.2

  • move cli to jaguar_http_cli
  • async call on interceptors

0.0.1

  • Initial version, created by Stagehand

example/example.dart

library jaguar_http.example;

import 'dart:async';
import 'package:http/http.dart';
import 'package:jaguar_http/jaguar_http.dart';
import 'package:jaguar_serializer/jaguar_serializer.dart';
import 'models/user.dart';

part 'example.g.dart';

/// definition
@JaguarHttp(name: "Api")
abstract class ApiDefinition {
  @Get("/users/:id")
  Future<JaguarResponse<User>> getUserById(@Param() String id);

  @Post("/users")
  Future<JaguarResponse<User>> postUser(@Body() User user);

  @Put("/users/:uid")
  Future<JaguarResponse<User>> updateUser(
      @Param("uid") String userId, @Body() User user);

  @Delete("/users/:id")
  Future<JaguarResponse> deleteUser(@Param() String id);

  @Get("/users")
  Future<JaguarResponse<List<User>>> search(
      {@QueryParam("n") String name, @QueryParam("e") String email});
}

JsonRepo repo = new JsonRepo()..add(new UserSerializer());

void main() {
  ApiDefinition api = new Api(
      client: new IOClient(),
      baseUrl: "http://localhost:9000",
      serializers: repo)
    ..requestInterceptors.add((JaguarRequest req) {
      req.headers["Authorization"] = "TOKEN";
      return req;
    });

  api.getUserById("userId").then((JaguarResponse res) {
    print(res);
  }, onError: (e) {
    print(e);
  });
}

Use this package as a library

1. Depend on it

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


dependencies:
  jaguar_http: ^0.0.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support 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_http/jaguar_http.dart';
  
Version Uploaded Documentation Archive
0.0.2+1 Jan 7, 2018 Go to the documentation of jaguar_http 0.0.2+1 Download jaguar_http 0.0.2+1 archive
0.0.2 Jan 7, 2018 Go to the documentation of jaguar_http 0.0.2 Download jaguar_http 0.0.2 archive
0.0.1 Jul 17, 2017 Go to the documentation of jaguar_http 0.0.1 Download jaguar_http 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
74
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
37
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0