jaguar_http_cli 0.0.2+1 copy "jaguar_http_cli: ^0.0.2+1" to clipboard
jaguar_http_cli: ^0.0.2+1 copied to clipboard

Dart 1 only

Cli for Jaguar Http, Api generator inspired by Retrofit for Dart.

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);
  });
}
0
likes
25
pub points
0%
popularity

Publisher

unverified uploader

Cli for Jaguar Http, Api generator inspired by Retrofit for Dart.

Homepage

License

BSD-3-Clause (LICENSE)

Dependencies

analyzer, build, build_runner, code_builder, http, jaguar_generator_config, jaguar_http, logging, source_gen

More

Packages that depend on jaguar_http_cli