|
|
@@ -3,42 +3,42 @@
|
|
|
This document will provide an overview of the gRPC API for Swift.
|
|
|
It follows a standard form used by each language-platform implementation.
|
|
|
|
|
|
-##Basic Functionality
|
|
|
+## Basic Functionality
|
|
|
|
|
|
The following examples use [echo.proto](Examples/Echo/echo.proto) to demonstrate
|
|
|
basic gRPC operation and generated code.
|
|
|
|
|
|
-###How is a New Stub Created?
|
|
|
+### How is a New Stub Created?
|
|
|
|
|
|
Swift gRPC client and server code is generated by the `protoc-gen-swiftgrpc` plugin.
|
|
|
The plugin is called from `protoc` and can be invoked for `echo.proto` like this:
|
|
|
|
|
|
protoc Examples/Echo/echo.proto --proto_path=Examples/Echo --swiftgrpc_out=.
|
|
|
|
|
|
-###Simple Request-Response RPC: Client-side RPC
|
|
|
+### Simple Request-Response RPC: Client-side RPC
|
|
|
|
|
|
var requestMessage = Echo_EchoRequest(text:message)
|
|
|
print("Sending: " + requestMessage.text)
|
|
|
let responseMessage = try service.get(requestMessage)
|
|
|
print("get received: " + responseMessage.text)
|
|
|
|
|
|
-###Simple Request-Response RPC: Server Implementation of RPC
|
|
|
+### Simple Request-Response RPC: Server Implementation of RPC
|
|
|
|
|
|
// get returns requests as they were received.
|
|
|
func get(request : Echo_EchoRequest) throws -> Echo_EchoResponse {
|
|
|
return Echo_EchoResponse(text:"Swift echo get: " + request.text)
|
|
|
}
|
|
|
|
|
|
-###Show how Client does two RPCs sequentially
|
|
|
+### Show how Client does two RPCs sequentially
|
|
|
|
|
|
|
|
|
-###Show how Client does two RPCs asynchronously
|
|
|
+### Show how Client does two RPCs asynchronously
|
|
|
|
|
|
|
|
|
-###Any code for handling incoming RPC on server that might need to be written
|
|
|
+### Any code for handling incoming RPC on server that might need to be written
|
|
|
|
|
|
|
|
|
-###Server Streaming RPC: Client-side code
|
|
|
+### Server Streaming RPC: Client-side code
|
|
|
|
|
|
let requestMessage = Echo_EchoRequest(text:message)
|
|
|
print("Sending: " + requestMessage.text)
|
|
|
@@ -54,7 +54,7 @@ The plugin is called from `protoc` and can be invoked for `echo.proto` like this
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-###Server Streaming RPC: Server-side code
|
|
|
+### Server Streaming RPC: Server-side code
|
|
|
|
|
|
// expand splits a request into words and returns each word in a separate message.
|
|
|
func expand(request : Echo_EchoRequest, session : Echo_EchoExpandSession) throws -> Void {
|
|
|
@@ -67,7 +67,7 @@ The plugin is called from `protoc` and can be invoked for `echo.proto` like this
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-###How is a Server Created?
|
|
|
+### How is a Server Created?
|
|
|
|
|
|
var done = NSCondition()
|
|
|
let echoProvider = EchoProvider()
|
|
|
@@ -92,13 +92,13 @@ The plugin is called from `protoc` and can be invoked for `echo.proto` like this
|
|
|
done.wait()
|
|
|
done.unlock()
|
|
|
|
|
|
-##Advanced
|
|
|
+## Advanced
|
|
|
|
|
|
-###RPC canceling on client side
|
|
|
+### RPC canceling on client side
|
|
|
|
|
|
-###Code to look for and handle cancelled RPC on Server side
|
|
|
+### Code to look for and handle cancelled RPC on Server side
|
|
|
|
|
|
-###Client Streaming RPC: Client-side code
|
|
|
+### Client Streaming RPC: Client-side code
|
|
|
|
|
|
let collectCall = try service.collect()
|
|
|
let parts = message.components(separatedBy:" ")
|
|
|
@@ -110,7 +110,7 @@ The plugin is called from `protoc` and can be invoked for `echo.proto` like this
|
|
|
}
|
|
|
let responseMessage = try collectCall.CloseAndReceive()
|
|
|
|
|
|
-###Client Streaming RPC: Server-side code
|
|
|
+### Client Streaming RPC: Server-side code
|
|
|
|
|
|
// collect collects a sequence of messages and returns them concatenated when the caller closes.
|
|
|
func collect(session : Echo_EchoCollectSession) throws -> Void {
|
|
|
@@ -129,11 +129,11 @@ The plugin is called from `protoc` and can be invoked for `echo.proto` like this
|
|
|
try session.SendAndClose(response)
|
|
|
}
|
|
|
|
|
|
-###Flow control interactions while sending & receiving messages
|
|
|
+### Flow control interactions while sending & receiving messages
|
|
|
|
|
|
-###Flow control and buffer pool : Control API
|
|
|
+### Flow control and buffer pool : Control API
|
|
|
|
|
|
-###Bi Directional Streaming : Client-side code
|
|
|
+### Bi Directional Streaming : Client-side code
|
|
|
|
|
|
var done = NSCondition()
|
|
|
let updateCall = try service.update()
|
|
|
@@ -167,7 +167,7 @@ The plugin is called from `protoc` and can be invoked for `echo.proto` like this
|
|
|
done.wait()
|
|
|
done.unlock()
|
|
|
|
|
|
-###Bi Directional Streaming : Server-side code
|
|
|
+### Bi Directional Streaming : Server-side code
|
|
|
|
|
|
// update streams back messages as they are received in an input stream.
|
|
|
func update(session : Echo_EchoUpdateSession) throws -> Void {
|
|
|
@@ -186,4 +186,4 @@ The plugin is called from `protoc` and can be invoked for `echo.proto` like this
|
|
|
try session.Close()
|
|
|
}
|
|
|
|
|
|
-###Any stub deletion/cleanup code needed
|
|
|
+### Any stub deletion/cleanup code needed
|