Client-side library that depends on SwiftGRPC which is a library of gRPC written in Swift. Basically it is used the function of Core part of SwiftGRPC, but it is made to make client implementation easier.
WARNING : If there is the breaking change in SwiftGRPC, this library may not be updatable.
The following two modules are included.
SwiftGRPCClient
It is a plugin to use when running at runtime. Link to the application or framework.
protoc-gen-swiftgrpc-client
It is a Protocol Buffer’s plugin for creating the functions necessary to use SwiftGRPCClient. Use protoc to generate .swift from .proto.
SwiftGRPCClient
If you use SwiftGRPC, you can do Unary connection using generated protocol or struct as follows.
let service = Echo_EchoServiceClient(address: "YOUR_SERVER_ADDRESS")
var requestMessage = Echo_EchoRequest()
requestMessage.text = "message"
_ = try? service.get(requestMessage) { responseMessage, callResult in
}
The get method above can get a message by sending arbitrary message, but with this method you can not get the information of the logged-in user. For example, if you want to get user information, you will need to prepare the following methods.
var requestUser = Example_UserRequest()
requestUser.id = "user_id"
_ = try? service.getUser(requestUser) { responseUser, callResult in
}
In this way, when connecting using a certain request, a special method is required to execute the request.
With SwiftGRPCClient, data is the only method to make a Unary request.
let session = Session(address: "YOUR_SERVER_ADDRESS")
session.stream(with: EchoUnaryRequest(text: "message"))
.data { result in
}
It is possible to get the user’s login information just by changing the request.
session.stream(with: GetUserRequest(id: "user_id"))
.data { result in
}
protoc-gen-swiftgrpc-client is a plugin for Protocol Buffers. It automatically defines requests, responses and methods used when connecting using SwiftGRPCClient.
Swift gRPC Client
Client-side library that depends on SwiftGRPC which is a library of gRPC written in Swift. Basically it is used the function of
Core
part ofSwiftGRPC
, but it is made to make client implementation easier.The following two modules are included.
SwiftGRPCClient
It is a plugin to use when running at runtime. Link to the application or framework.
protoc-gen-swiftgrpc-client
It is a Protocol Buffer’s plugin for creating the functions necessary to use
SwiftGRPCClient
. Useprotoc
to generate.swift
from.proto
.SwiftGRPCClient
If you use
SwiftGRPC
, you can doUnary
connection using generatedprotocol
orstruct
as follows.The
get
method above can get amessage
by sending arbitrarymessage
, but with this method you can not get the information of the logged-in user. For example, if you want to get user information, you will need to prepare the following methods.In this way, when connecting using a certain request, a special method is required to execute the request.
With
SwiftGRPCClient
,data
is the only method to make aUnary
request.It is possible to get the user’s login information just by changing the request.
See also SwiftGRPCClient document.
Requirements
How to Install
CocoaPods
Add the following to your
Podfile
:protoc-gen-swiftgrpc-client
protoc-gen-swiftgrpc-client
is a plugin for Protocol Buffers. It automatically defines requests, responses and methods used when connecting usingSwiftGRPCClient
.See also protoc-gen-swiftgrpc-client document.
Requirements
How to get plugin
Execute the following command.
Explain generated code
As an example, prepare the following
.proto
.protoc
creates.swift
file.Define the
Request
object usingprotocol
in the generated.swift
.LICENSE
Under the MIT license. See LICENSE file for details.