jaguar_http 0.0.2+1
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+1
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';
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
6
|
Health:
Code health derived from static analysis.
[more]
|
--
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
--
|
Overall:
Weighted score of the above.
[more]
|
3
|
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.
Analysis 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://dart.dev/dart-2#migration.
Maintenance issues and suggestions
Make sure dartdoc
successfully runs on your package's source files. (-10 points)
Dependencies were not resolved.
Dependencies
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=1.20.1 <2.0.0 |