chopper2 library

Chopper is an http client generator using source_gen and inspired by Retrofit.

Getting Started

Classes

Body
Declares the Body of Post, Put, and Patch requests
ChopperApi
Defines a Chopper API.
ChopperClient
ChopperClient is the main class of the Chopper API Used to manager services, encode data, intercept request, response and error.
ChopperService
Used by generator to generate apis
Converter
Converter is is used to convert body of Request or Response convertRequest is call before RequestInterceptor and convertResponse just after the http response, before ResponseInterceptor.
CurlInterceptor
Interceptor that print a curl request thanks @edwardaux
Delete
Defines a method as an HTTP DELETE request.
ErrorConverter
FactoryConverter
Field
Define a field for a x-www-form-urlencoded request. Automatically binds to the name of the method parameter.
FileField
Use it to define a file field for a Multipart request.
FormUrlEncodedConverter
Get
Defines a method as an HTTP GET request.
Defined a method as an HTTP HEAD request.
Passes a value to the header of the request.
HeadersInterceptor
Add headers to each request
HttpLoggingInterceptor
HttpMethod
JsonConverter
json.encode on Request and json.decode on Response Also add application/json header to each request
Method
Defines an HTTP method.
Multipart
Defines a multipart request.
Part
Use it to define a part of a Multipart request.
PartFile
Use it to define a file field for a Multipart request.
PartValue<T>
PartValueFile<T>
Patch
Defines a method as an HTTP PATCH request. Use the Body annotation to pass data to send.
Path
Provides a parameter in the url.
Post
Defines a method as an HTTP POST request.
Put
Defines a method as an HTTP PUT request.
Query
Provides the query parameters of a request.
QueryMap
Provides query parameters of a request as Map<String, dynamic>.
Request
HTTP request generated by Chopper
RequestInterceptor
Interface to implements a request interceptor. Not recommended to modify body inside interceptor, see Converter to encode body request.
Response<BodyType>
Wrapper arround http.BaseResponse
ResponseInterceptor
Interface to implements a response interceptor. Not recommended to modify body inside interceptor, see Converter to decode body response.

Constants

body → const Body
Body()
contentTypeKey → const String
'content-type'
formEncodedHeaders → const String
'application/x-www-form-urlencoded'
jsonHeaders → const String
'application/json'
multipart → const Multipart

Properties

allowedInterceptorsType List<Type>
chopperLogger Logger
final

Functions

applyHeader(Request request, String name, String value, {bool override = true}) Request
Apply value to the header field name of the request if override is true, it will erase already present headers with the new value
applyHeaders(Request request, Map<String, String> headers, {bool override = true}) Request
Apply given headers to the request if override is true, it will erase already present headers with the new value
buildUri(String baseUrl, String url, Map<String, dynamic> parameters) Uri
isTypeOf<ThisType, OfType>() bool
toHttpRequest(dynamic body, String method, Uri uri, Map<String, String> headers) Future<Request>
toMultipartRequest(List<PartValue> parts, String method, Uri uri, Map<String, String> headers) Future<MultipartRequest>
toStreamedRequest(Stream<List<int>> bodyStream, String method, Uri uri, Map<String, String> headers) Future<StreamedRequest>

Typedefs

ConvertRequest = FutureOr<Request> Function(Request request)
ConvertResponse<T> = FutureOr<Response> Function(Response response)
DynamicResponseInterceptorFunc = FutureOr<Response> Function(Response response)
RequestInterceptorFunc = FutureOr<Request> Function(Request request)
ResponseInterceptorFunc1 = FutureOr<Response<BodyType>> Function<BodyType>(Response<BodyType> response)
ResponseInterceptorFunc2 = FutureOr<Response<BodyType>> Function<BodyType, InnerType>(Response<BodyType> response)