flutter_annotation_http

Last updated:

0 purchases

flutter_annotation_http Image
flutter_annotation_http Images
Add to Cart

Description:

flutter annotation http

flutter_annotation_http #
Annotation-based Http library.
Example #

Import

import 'dart:convert';

import 'package:flutter_annotation_http/flutter_annotation_http.dart';
import 'package:http/http.dart' as http;
copied to clipboard

Basic

@Endpoint(
baseUrl: 'https://jsonplaceholder.typicode.com',
parameters: {'x-app-platform': 'ios'},
headers: {'x-lang-platform': 'Dart'},
)
abstract class JsonPlaceholderApi {
factory JsonPlaceholderApi() => _$JsonPlaceholderApiImpl();

@GET('/todos')
Future<List<TodoModel>> getTodos({String? title});

@POST('/todos')
Future<TodoModel> createTodo(AddTodo data);
}
copied to clipboard

Custom Headers

@PATCH('/todos/{id}', headers: {'x-user-tag': '1'})
Future<TodoModel> patchTodo(String title);

@PATCH('/todos/{id}')
Future<TodoModel> patchTodo(@RequestHeader(name: 'x-user-type') String type);
copied to clipboard

Path Variable

@GET('/todos/{id}')
Future<TodoModel> getTodo(@PathVariable() String id);
copied to clipboard

Custom encode

@JsonObject()
class AddTodo {
final String title;
final String body;
final int userId;

AddTodo({required this.title, required this.body, required this.userId});

Map<String, dynamic> toJson() => _$AddTodoToJson(this);
}

@PUT('/todos/{id}', consume: RequestMapping.jsonHeader)
Future<TodoModel> updateTodo(@RequestBody(_todoToJson) AddTodo data);

Map _todoToJson(AddTodo todo) => todo.toJson();
copied to clipboard

Upload file

@Multipart('/upload', timeout: 60 * 1000)
Future<void> upload(String from,
@FilePart(filename: 'image', contentType: 'image/jpeg') String imagePath);
copied to clipboard

Raw response

@DELETE('/todos/{id}')
Future<http.Response> deleteTodo(@PathVariable() int id);

@GET('/bytes/{n}', produce: RequestMapping.byteHeader)
Future<Uint8List> runBytes(@PathVariable() int n);

@GET('/json', produce: RequestMapping.jsonHeader)
Future<Map> getJson();

@GET('/robots.txt', produce: RequestMapping.textHeader)
Future<String> getRobotsTxt();
copied to clipboard

Http chain

factory JsonPlaceholderApi([HttpChain? chain]) => _$JsonPlaceholderApiImpl(chain);
copied to clipboard

Cancel request

@GET('/status')
Future<void> cancelRequest(CancelToken cancelToken);
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.