Dart RPC响应有204个无内容

时间:2018-07-05 09:45:30

标签: dart dart-rpc

我正在尝试使用dart包在dart-rpc中创建api,这是我的ApiMethod()

@override
  @ApiMethod(name: "Create new user", method: 'POST', path: 'create')
  Future<User> create(UserRequest t) async {
    print('Called here with ${t.emailId}');
    var user = await _db.createUser(new User(t.name, t.emailId, t.password));
    print('${user.toJson()}');
    return user;
  }

一切正常,db中存在新用户,但是响应为204(无内容)

我的回复user模型如下:

class User {
  static int ids = 0;
  int _id;
  String _name;
  String _emailId;
  String _password;

  User(this._name, this._emailId, this._password);

  String get password => _password;

  String get emailId => _emailId;

  String get name => _name;

  int get id => _id;

  set id(int value) {
    _id = value;
  }

  static int incrementIdAndGet() {
    return ++ids;
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is User &&
          runtimeType == other.runtimeType &&
          _emailId == other._emailId;

  @override
  int get hashCode => _emailId.hashCode;

  Map<String, dynamic> toJson() => {
        'email': _emailId,
        'name': _name,
      };
}

但是当我手动撰写地图并返回地图时就可以使用。

0 个答案:

没有答案