Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yamashou/proto-to-dart-http
proto-to-dart-http is a command line tool to generate http api client from protofile.
https://github.com/yamashou/proto-to-dart-http
dart golang protobuf
Last synced: 3 months ago
JSON representation
proto-to-dart-http is a command line tool to generate http api client from protofile.
- Host: GitHub
- URL: https://github.com/yamashou/proto-to-dart-http
- Owner: Yamashou
- Created: 2019-04-17T13:40:19.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-18T06:14:45.000Z (almost 6 years ago)
- Last Synced: 2024-06-20T12:24:44.339Z (7 months ago)
- Topics: dart, golang, protobuf
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# proto-to-dart-http
this repository is a command line tool to generate http api client from protofile.
# Usage
```
proto-to-dart-http \
-i "proto/" \
-o .
-p project-name \
-pp /proto/v1/ \
api/v1/*.proto```
- *-i* : protfile root path
- *-o* : generated file path
- *-p* : project name
- *-pp*: dart project path# Example
There are example in `example/`.
example.proto
```example.protosyntax = "proto3";
import "google/api/annotations.proto";
service UserService {
rpc GetUser(GetUserRequest) returns (GetUserResponse){
option (google.api.http) = {
post: "/UserService/GetUser"
body: "user"
additional_bindings {
post: "/UserService/GetUser2"
body: "*"
}
additional_bindings {
get: "/UserService/GetUser"
}
};
};
}message GetUserRequest {
User user = 1;
}message GetUserResponse {}
message User {
string user_id= 1;
string user_name = 2;
}
``````
$ cd example
$ proto-to-dart-http -i "./,$GOPATH/src/github.com/googleapis/googleapis" -o . -p example -pp /proto/v1/ *.proto
``````
import 'package:http/http.dart' as http;
import 'package:example/proto/v1/test.pb.dart'; // this path is decided path of `-pp`
class ExampleClient {
String baseUrl;
ExampleClient(String baseUrl) {this.baseUrl = baseUrl;}
Future getUser(GetUserRequest body, Map headers) async {
final response = await http.post(
this.baseUrl + "/UserService/GetUser",
body: body.writeToBuffer(),
headers: headers);final GetUserResponse res = GetUserResponse.fromBuffer(response.bodyBytes);
return res;
}Future getUser(GetUserRequest body, Map headers) async {
final response = await http.post(
this.baseUrl + "/UserService/GetUser2",
body: body.writeToBuffer(),
headers: headers);final GetUserResponse res = GetUserResponse.fromBuffer(response.bodyBytes);
return res;
}Future getUser(GetUserRequest body, Map headers) async {
final response = await http.get(
this.baseUrl + "/UserService/GetUser",
body: body.writeToBuffer(),
headers: headers);final GetUserResponse res = GetUserResponse.fromBuffer(response.bodyBytes);
return res;
}}
```