http_annotations 0.0.3 copy "http_annotations: ^0.0.3" to clipboard
http_annotations: ^0.0.3 copied to clipboard

discontinued
outdated

http annotation for code generation

Provides annotations for http code gen

  1. Add the generated file as a part of this file and annotate your class with @HttpApi()

    part 'file_name.http.dart';
    
    @HttpApi('http://localhost:3000')
    abstract class MyApi {
      // create a factory redirect (this is required)
      factory MyApi() = _MyApi;
    
      // optional close method to dispose resources
      void close();
    }
    
  2. Annotate methods with appropirate HTTP Method and path

    @Route.get('/api/v0/todos')
    Future<List<Todo>> getTodos();
    

    Parameter replacement support

    @Route.get('/api/v0/todo/{id}')
    Future<Todo> getTodo(int id);
    
  3. Annotate methods with headers

    @Route.get('/api/v0/todos')
    @Header.contentTypeJson()
    @Header('cache', 'never')
    Future<List<Todo>> getTodos();
    
  4. Annotate methods with HTTP status codes that have body

    By default only status code 200 is supported Example, if you want to add for status codes 400 and 401

    @Route.get('/api/v0/user/login')
    @StatusCodesWithBody([200, 400, 401])
    Future<LoginResponse> login();
    
  5. Annotate a parameter with the body of the request (post, put, patch, delete)

    @Route.post('/api/v0/todo')
    Future<CreateTodoResponse>(@Body() Map<String, dynamic> json);
    
  6. Annotate a parameter with query parameter

    @Route.get('/api/v0/todos')
    Future<List<Todo>>(
      @QueryParam() int page,
      @QueryParam('named_limit') int limit,
    );
    
2
likes
0
pub points
0%
popularity

Publisher

unverified uploader

http annotation for code generation

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

http

More

Packages that depend on http_annotations