packages.dart icon indicating copy to clipboard operation
packages.dart copied to clipboard

[network] Decorators

Open SergeShkurko opened this issue 5 years ago • 0 comments

Package name network

Describe the solution you'd like The ability to use decorators for example: @get('http://todo.api/todo/1') / @post('http://todo.api/todo')

Additional context Proposal example:

class TodoApi {
  @get<JsonApiRequest, JsonApiResponse>('http://todo.api/todo')
  Future<Iterable<Todo>> getAll(JsonApiRequest request, JsonApiResponse response) async {
    return List.from(response.toMap).map((map) => Todo.fromMap(map));
  }

  @get<JsonApiRequest, JsonApiResponse>('http://todo.api/todo/${id}')
  Future<Todo> get(JsonApiRequest request, JsonApiResponse response) async {
    return Todo.fromMap(response.toMap);
  }

  @delete<JsonApiRequest, JsonApiResponse>('http://todo.api/todo/${id}')
  Future<Todo> delete(JsonApiRequest request, JsonApiResponse response) async {
    return response.toMap['success'] != null;
  }
}

TODO

  • [ ] JsonApiRequest
  • [ ] Get
  • [ ] Post
  • [ ] Delete
  • [ ] Put

SergeShkurko avatar Mar 12 '19 01:03 SergeShkurko