cinch

Creator: coderz1093

Last updated:

0 purchases

cinch Image
cinch Images

Languages

Categories

Add to Cart

Description:

cinch

cinch #

Usage #
dependencies:
cinch: ^4.1.1

dev_dependencies:
cinch_gen: ^4.1.1
copied to clipboard
Migration #

3.X.X to 4.0.0

run dart run build_runner build



Example #

test.dart

import 'package:cinch/cinch.dart';
part 'test.cinch.dart';
@ApiService('https://test.com/')
class TestApi extends _$TestApi {
TestApi() : super();

@Get('api/test1')
Future<Response> test(@Query('t1') int t1) async {
return _$test(t1);
}
}
copied to clipboard
Build #

terminal run dart run build_runner build

Support Http Method #

POST
GET
PUT
DELETE

application/x-www-form-urlencoded #
@formUrlEncoded
@Post('api/test')
Future<WebGlobalJson<Login>> test(@Field('t1') String t1) async {
return _$test(t1);
}
copied to clipboard
Path #
@formUrlEncoded
@Post('api/test/{path}')
Future<WebGlobalJson<Login>> test(@Path('path') String path) async {
return _$test(path);
}
copied to clipboard
URL #
import 'package:cinch/cinch.dart';
part 'test.cinch.dart';

class Web extends ApiService {
const Web() : super("https://test.com/");
}

@Web()
class TestApi extends _$TestApi {
TestApi() : super();
@Get('api/test1')
Future<Response> test(@Query('t1') int t1) async {
return _$test(t1);
}
}
copied to clipboard
Or
import 'package:cinch/cinch.dart';
part 'test.cinch.dart';

class Web with ApiUrlMixin {
@override
String get url => 'https://test.com/';

}

@ApiService.emptyUrl()
class TestApi extends _$TestApi with Web {
TestApi() : super();
@Get('api/test1')
Future<Response> test(@Query('t1') int t1) async {
return _$test(t1);
}
}
copied to clipboard
Multipart #
@ApiService('http://localhost:8080/')
class TestService extends _$TestService {
@Post('upload')
@multipart
Future<Response> upload(@Part('file') MultipartFile file) {
return _$upload(file);
}
}

void test() {
service.upload(MultipartFile.fromFileSync('/path/file.txt', filename: '上傳名稱.txt'));
service.upload(MultipartFile.fromBytes(bytes, filename: '上傳名稱.txt'));
}
copied to clipboard

Or use partMap

@ApiService('http://localhost:8080/')
class TestService extends _$TestService {
@Post('multiUpload')
@multipart
Future<Response> multiUpload(@Part('flag') int flag,
@partMap Map<String, MultipartFile> file) {
return _$multiUpload(flag, file);
}
}

void test() {
service.multiUpload(88, {
"file0": MultipartFile.fromFileSync(
'/Downloads/Resume.docx', filename: 'test0.docx'),
"file1": MultipartFile.fromFileSync(
'/Downloads/Resume.docx', filename: 'test1.docx')
});

service.multiUpload(99, {
for (var i = 0; i < 5; i++)
"file$i": MultipartFile.fromFileSync(
'/Downloads/Resume.docx', filename: 'test$i.docx'),
});
}
copied to clipboard
ValidateStatus #
import 'package:cinch/cinch.dart';
part 'test.cinch.dart';
@ApiService('https://test.com/')
class TestApi extends _$TestApi {
TestApi() : super(validateStatus: (status) => status == 404);

/// If set validateStatus in method, constructor validateStatus will be ignored.
@Get('api/test1', validateStatus: [403])
Future<Response> test(@Query('t1') int t1) async {
return _$test(t1);
}
}
copied to clipboard
Header #
import 'package:cinch/cinch.dart';
part 'test.cinch.dart';
@ApiService('https://test.com/')
class TestApi extends _$TestApi {

@Get('api/test1')
Future<Response> test(@Header(HttpHeaders.authorizationHeader) String token) async {
return _$test(token);
}
}
copied to clipboard
License #
MIT License

Copyright (c) 2020 tatsuyuki

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
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.