GRPCCore
A gRPC library for Swift written natively in Swift.
import GRPCCore
Module information
- Declarations
- 473
- Symbols
- 803
Overview
Package structure
gRPC Swift is distributed across multiple Swift packages. These are:
grpc-swift
(this package) containing core gRPC abstractions and an in-process transport.GitHub repository:
grpc/grpc-swift
Documentation: hosted on the Swift Package Index
grpc-swift-nio-transport
contains high-performance HTTP/2 transports built on top of SwiftNIO.GitHub repository:
grpc/grpc-swift-nio-transport
Documentation: hosted on the Swift Package Index
grpc-swift-protobuf
contains runtime serialization components to interoperate with SwiftProtobuf as well as a plugin for the Protocol Buffers compiler,protoc
.GitHub repository:
grpc/grpc-swift-protobuf
Documentation: hosted on the Swift Package Index
grpc-swift-extras
contains optional runtime components and integrations with other packages.GitHub repository:
grpc/grpc-swift-extras
Documentation: hosted on the Swift Package Index
This package, and this module (GRPCCore
) in particular, include higher level documentation such as tutorials.
Modules in this package
GRPCCore
(this module) contains core abstractions, currency types and runtime components for gRPC Swift.GRPCInProcessTransport
contains an in-process implementation of theClientTransport
andServerTransport
protocols.GRPCodeGen
contains components for building a code generator.
Tutorials
Quick Start: Hello, World!
This tutorial walks you through the canonical “Hello, World!” program for gRPC Swift. You’ll learn how to implement a service using generated stubs, then you’ll learn to configure and use a gRPC server. You’ll also see how to create a client and use it to call the server.
Read MoreThe Basics: Route Guide
Follow this tutorial to learn how to create a gRPC service and client from scratch. You’ll learn how to define a service in a
Read More.proto
file, generate server and client code using the Protocol Buffer compiler, and use gRPC Swift to write a simple client and server for your service.
Essentials
Generating stubs with gRPC Swift Protobuf
Learn how to generate stubs for gRPC Swift from a service defined using the Protocol Buffers IDL.
Read MoreErrors
Learn about the different error mechanisms in gRPC and how to use them.
Read More
Project Information
Compatibility
Learn which versions of Swift are supported by gRPC Swift and how this changes over time.
Read MorePublic API
Understand what constitutes the public API of gRPC Swift and the commitments made by the maintainers.
Read More
Getting involved
Resources for developers working on gRPC Swift:
Design
This article provides a high-level overview of the design of gRPC Swift.
Read MoreBenchmarks
This article discusses benchmarking in
Read Moregrpc-swift
.
Client and Server
class GRPCClient<Transport>
A gRPC client.
class GRPCServer<Transport>
A gRPC server.
func withGRPCClient<Transport, Result>(transport: Transport, interceptors: [any ClientInterceptor], isolation: isolated (any Actor)?, handleClient: (GRPCClient<Transport>) async throws -> Result
) async throws -> Result Creates and runs a new client with the given transport and interceptors.
func withGRPCClient<Transport, Result>(transport: Transport, interceptorPipeline: [ConditionalInterceptor<any ClientInterceptor>], isolation: isolated (any Actor)?, handleClient: (GRPCClient<Transport>) async throws -> Result
) async throws -> Result Creates and runs a new client with the given transport and interceptors.
func withGRPCServer<Transport, Result>(transport: Transport, services: [any RegistrableRPCService], interceptors: [any ServerInterceptor], isolation: isolated (any Actor)?, handleServer: (GRPCServer<Transport>) async throws -> Result
) async throws -> Result Creates and runs a gRPC server.
func withGRPCServer<Transport, Result>(transport: Transport, services: [any RegistrableRPCService], interceptorPipeline: [ConditionalInterceptor<any ServerInterceptor>], isolation: isolated (any Actor)?, handleServer: (GRPCServer<Transport>) async throws -> Result
) async throws -> Result Creates and runs a gRPC server.
Request and response types
struct ClientRequest<Message>
A request created by the client for a single message.
struct StreamingClientRequest<Message>
A request created by the client for a stream of messages.
struct ClientResponse<Message>
A response for a single message received by a client.
struct StreamingClientResponse<Message>
A response for a stream of messages received by a client.
struct ServerRequest<Message>
A request received at the server containing a single message.
struct StreamingServerRequest<Message>
A request received at the server containing a stream of messages.
struct ServerResponse<Message>
A response for a single message sent by a server.
struct StreamingServerResponse<Message>
A response for a stream of messages sent by a server.
Service definition and routing
protocol RegistrableRPCService
An RPC service which can register its methods with an
RPCRouter
.struct RPCRouter<Transport>
Stores and provides handlers for RPCs.
Interceptors
protocol ClientInterceptor
A type that intercepts requests and response for clients.
protocol ServerInterceptor
A type that intercepts requests and response for server.
struct ClientContext
A context passed to the client containing additional information about the RPC.
struct ServerContext
Additional information about an RPC handled by a server.
struct ConditionalInterceptor<Interceptor>
Describes the conditions under which an interceptor should be applied.
RPC descriptors
struct MethodDescriptor
A description of a method on a service.
struct ServiceDescriptor
A description of a service.
Service config
struct ServiceConfig
Service configuration values.
struct MethodConfig
Configuration values for executing an RPC.
struct HedgingPolicy
Policy for hedging an RPC.
struct RetryPolicy
Policy for retrying an RPC.
struct RPCExecutionPolicy
Whether an RPC should be retried or hedged.
Serialization
protocol MessageSerializer<Message>
Serializes a message into a sequence of bytes.
protocol MessageDeserializer<Message>
Deserializes a sequence of bytes into a message.
struct CompressionAlgorithm
Message compression algorithms.
struct CompressionAlgorithmSet
A set of compression algorithms.
Transport protocols and supporting types
protocol ClientTransport<Bytes>
A type that provides a long-lived bidirectional communication channel to a server.
protocol ServerTransport<Bytes>
A type that provides a bidirectional communication channel with a client.
enum RPCRequestPart<Bytes>
Part of a request sent from a client to a server in a stream.
enum RPCResponsePart<Bytes>
Part of a response sent from a server to a client in a stream.
struct Status
A status object represents the outcome of an RPC.
struct Metadata
A collection of metadata key-value pairs, found in RPC streams.
class RetryThrottle
A throttle used to rate-limit retries and hedging attempts.
struct RPCStream<Inbound, Outbound>
A bidirectional communication channel between a client and server for a given method.
protocol RPCWriterProtocol<Element>
A type into which values can be written indefinitely.
protocol ClosableRPCWriterProtocol<Element>
A type into which values can be written until it is finished.
struct RPCWriter<Element>
A type-erasing
RPCWriterProtocol
.struct RPCAsyncSequence<Element, Failure>
A type-erasing
AsyncSequence
.
Cancellation
func withServerContextRPCCancellationHandle<Success, Failure>((ServerContext.RPCCancellationHandle) async throws(Failure) -> Success
) async throws(Failure) -> Success Provides scoped access to a server RPC cancellation handle.
func withRPCCancellationHandler<Result, Failure>(operation: () async throws(Failure) -> Result, onCancelRPC: @escaping () -> Void
) async throws(Failure) -> Result Execute an operation with an RPC cancellation handler that’s immediately invoked if the RPC is canceled.
Errors
struct RPCError
An error representing the outcome of an RPC.
protocol RPCErrorConvertible
A value that can be converted to an
RPCError
.struct RuntimeError
An error thrown at runtime.