Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ahyangnb/generate_api_path


https://github.com/ahyangnb/generate_api_path

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

# Generate api path.

The generate_api_path can be generated different api path file for encode api request.

## Generate result.

debug mode:

```dart
class UrlGenerator {
static const String userInfo = '/user/info';
static const String systemHiNotice = '/system/hi/notice';
static const String flowerHiGood = '/flower/hi/good';
}
```

release mode:

```dart
class UrlGenerator {
static const String userInfo = '00000000-00000000-00000-000000000000';
static const String systemHiNotice = '00000000-00000000-00000-000000000001';
static const String flowerHiGood = '00000000-00000000-00000-000000000002';
}
```

## Usage

import the `generate_api_path` and `analyzer` plugin in `pubspec.yaml` file.

```yaml
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.6
# This one.
generate_api_path: ^0.0.1

dev_dependencies:
flutter_test:
sdk: flutter
# This one.
analyzer: ^6.2.0
```

make a file `origin.txt` on `material` directory, and write the api path in it.

the key is code and the value is the path.

```txt
00000000-00000000-00000-000000000000 -> /user/info
00000000-00000000-00000-000000000001 -> /system/hi/notice
00000000-00000000-00000-000000000002 -> /flower/hi/good
```

then run the command:

```shell
dart run generate_api_path:create --origin_file_path material/origin.txt --target_file_path lib/gen/http/api_mapping_generate.dart --mode debug
```

or

```shell
dart run generate_api_path:create --origin_file_path material/origin.txt --target_file_path lib/gen/http/api_mapping_generate.dart --mode release
```

it will generate a file `api_mapping_generate.dart` in `lib/gen` directory and the content is:

```dart
class UrlGenerator {
static const String userInfo = '/user/info';
static const String systemHiNotice = '/system/hi/notice';
static const String flowerHiGood = '/flower/hi/good';
}
```

or

```dart
class UrlGenerator {
static const String userInfo = '00000000-00000000-00000-000000000000';
static const String systemHiNotice = '00000000-00000000-00000-000000000001';
static const String flowerHiGood = '00000000-00000000-00000-000000000002';
}
```

more detail see the [example](example) directory.