title: Making network call to a gRPC API with swift
body: <p>I have never worked with grpc and have some questions. I have a swift UI app and need to make a network call via grpc. I am using the package grpc-swift</p>
  <p>i have the proto file converted to the .pb.swift and .grpc.swift</p>
  <p>any help on how to make the authentication call would be much appreciated</p>
  <p>partner_api.grpc.swift</p>
  <pre><code>//
  // DO NOT EDIT.
  //
  // Generated by the protocol buffer compiler.
  // Source: partner_api.proto
  //
  
  //
  // Copyright 2018, gRPC Authors All rights reserved.
  //
  // Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  //
  import GRPC
  import NIO
  import SwiftProtobuf
  
  
  /// The methods available from the Emporia Energy Partner API.  The Emporia API is available via gRPC at 
  ///   URL:  partner-api.emporiaenergy.com 
  ///   PORT: 50051
  ///
  /// Usage: instantiate `Protos_PartnerApiClient`, then call methods of this protocol to make API calls.
  internal protocol Protos_PartnerApiClientProtocol: GRPCClient {
    var serviceName: String { get }
    var interceptors: Protos_PartnerApiClientInterceptorFactoryProtocol? { get }
  
    func authenticate(
      _ request: Protos_AuthenticationRequest,
      callOptions: CallOptions?
    ) -&gt; UnaryCall&lt;Protos_AuthenticationRequest, Protos_AuthenticationResponse&gt;
  
    func getDevices(
      _ request: Protos_DeviceInventoryRequest,
      callOptions: CallOptions?
    ) -&gt; UnaryCall&lt;Protos_DeviceInventoryRequest, Protos_DeviceInventoryResponse&gt;
  
    func getUsageData(
      _ request: Protos_DeviceUsageRequest,
      callOptions: CallOptions?
    ) -&gt; UnaryCall&lt;Protos_DeviceUsageRequest, Protos_DeviceUsageResponse&gt;
  
    func getOutletStatus(
      _ request: Protos_DeviceListRequest,
      callOptions: CallOptions?
    ) -&gt; UnaryCall&lt;Protos_DeviceListRequest, Protos_OutletStatusResponse&gt;
  
    func setOutletStatus(
      _ request: Protos_OutletStatusRequest,
      callOptions: CallOptions?
    ) -&gt; UnaryCall&lt;Protos_OutletStatusRequest, Protos_OutletStatusResponse&gt;
  }
  
  extension Protos_PartnerApiClientProtocol {
    internal var serviceName: String {
      return &quot;protos.PartnerApi&quot;
    }
  
    /// login with the email and password you use on the portal website and get back an auth_token
    ///
    /// - Parameters:
    ///   - request: Request to send to Authenticate.
    ///   - callOptions: Call options.
    /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
    internal func authenticate(
      _ request: Protos_AuthenticationRequest,
      callOptions: CallOptions? = nil
    ) -&gt; UnaryCall&lt;Protos_AuthenticationRequest, Protos_AuthenticationResponse&gt; {
      return self.makeUnaryCall(
        path: &quot;/protos.PartnerApi/Authenticate&quot;,
        request: request,
        callOptions: callOptions ?? self.defaultCallOptions,
        interceptors: self.interceptors?.makeAuthenticateInterceptors() ?? []
      )
    }
  
    /// get the collection of devices associated to your partner account, 
    /// optionally limited to devices related to one or more customer emails
    ///
    /// - Parameters:
    ///   - request: Request to send to GetDevices.
    ///   - callOptions: Call options.
    /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
    internal func getDevices(
      _ request: Protos_DeviceInventoryRequest,
      callOptions: CallOptions? = nil
    ) -&gt; UnaryCall&lt;Protos_DeviceInventoryRequest, Protos_DeviceInventoryResponse&gt; {
      return self.makeUnaryCall(
        path: &quot;/protos.PartnerApi/GetDevices&quot;,
        request: request,
        callOptions: callOptions ?? self.defaultCallOptions,
        interceptors: self.interceptors?.makeGetDevicesInterceptors() ?? []
      )
    }
  
    /// get usage data for one or more devices
    ///
    /// - Parameters:
    ///   - request: Request to send to GetUsageData.
    ///   - callOptions: Call options.
    /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
    internal func getUsageData(
      _ request: Protos_DeviceUsageRequest,
      callOptions: CallOptions? = nil
    ) -&gt; UnaryCall&lt;Protos_DeviceUsageRequest, Protos_DeviceUsageResponse&gt; {
      return self.makeUnaryCall(
        path: &quot;/protos.PartnerApi/GetUsageData&quot;,
        request: request,
        callOptions: callOptions ?? self.defaultCallOptions,
        interceptors: self.interceptors?.makeGetUsageDataInterceptors() ?? []
      )
    }
  
    /// determine if one or more Outlets are currently on
    ///
    /// - Parameters:
    ///   - request: Request to send to GetOutletStatus.
    ///   - callOptions: Call options.
    /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
    internal func getOutletStatus(
      _ request: Protos_DeviceListRequest,
      callOptions: CallOptions? = nil
    ) -&gt; UnaryCall&lt;Protos_DeviceListRequest, Protos_OutletStatusResponse&gt; {
      return self.makeUnaryCall(
        path: &quot;/protos.PartnerApi/GetOutletStatus&quot;,
        request: request,
        callOptions: callOptions ?? self.defaultCallOptions,
        interceptors: self.interceptors?.makeGetOutletStatusInterceptors() ?? []
      )
    }
  
    /// set one or more Outlets to be on or off.  
    /// only the outlets that were changed will be included in the OutletStatusResponse; outlets that
    /// aren't connected to the cloud or were already in the requested state won't be included
    ///
    /// - Parameters:
    ///   - request: Request to send to SetOutletStatus.
    ///   - callOptions: Call options.
    /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
    internal func setOutletStatus(
      _ request: Protos_OutletStatusRequest,
      callOptions: CallOptions? = nil
    ) -&gt; UnaryCall&lt;Protos_OutletStatusRequest, Protos_OutletStatusResponse&gt; {
      return self.makeUnaryCall(
        path: &quot;/protos.PartnerApi/SetOutletStatus&quot;,
        request: request,
        callOptions: callOptions ?? self.defaultCallOptions,
        interceptors: self.interceptors?.makeSetOutletStatusInterceptors() ?? []
      )
    }
  }
  
  internal protocol Protos_PartnerApiClientInterceptorFactoryProtocol {
  
    /// - Returns: Interceptors to use when invoking 'authenticate'.
    func makeAuthenticateInterceptors() -&gt; [ClientInterceptor&lt;Protos_AuthenticationRequest, Protos_AuthenticationResponse&gt;]
  
    /// - Returns: Interceptors to use when invoking 'getDevices'.
    func makeGetDevicesInterceptors() -&gt; [ClientInterceptor&lt;Protos_DeviceInventoryRequest, Protos_DeviceInventoryResponse&gt;]
  
    /// - Returns: Interceptors to use when invoking 'getUsageData'.
    func makeGetUsageDataInterceptors() -&gt; [ClientInterceptor&lt;Protos_DeviceUsageRequest, Protos_DeviceUsageResponse&gt;]
  
    /// - Returns: Interceptors to use when invoking 'getOutletStatus'.
    func makeGetOutletStatusInterceptors() -&gt; [ClientInterceptor&lt;Protos_DeviceListRequest, Protos_OutletStatusResponse&gt;]
  
    /// - Returns: Interceptors to use when invoking 'setOutletStatus'.
    func makeSetOutletStatusInterceptors() -&gt; [ClientInterceptor&lt;Protos_OutletStatusRequest, Protos_OutletStatusResponse&gt;]
  }
  
  internal final class Protos_PartnerApiClient: Protos_PartnerApiClientProtocol {
    internal let channel: GRPCChannel
    internal var defaultCallOptions: CallOptions
    internal var interceptors: Protos_PartnerApiClientInterceptorFactoryProtocol?
  
    /// Creates a client for the protos.PartnerApi service.
    ///
    /// - Parameters:
    ///   - channel: `GRPCChannel` to the service host.
    ///   - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
    ///   - interceptors: A factory providing interceptors for each RPC.
    internal init(
      channel: GRPCChannel,
      defaultCallOptions: CallOptions = CallOptions(),
      interceptors: Protos_PartnerApiClientInterceptorFactoryProtocol? = nil
    ) {
      self.channel = channel
      self.defaultCallOptions = defaultCallOptions
      self.interceptors = interceptors
    }
  }
  
  /// The methods available from the Emporia Energy Partner API.  The Emporia API is available via gRPC at 
  ///   URL:  partner-api.emporiaenergy.com 
  ///   PORT: 50051
  ///
  /// To build a server, implement a class that conforms to this protocol.
  internal protocol Protos_PartnerApiProvider: CallHandlerProvider {
    var interceptors: Protos_PartnerApiServerInterceptorFactoryProtocol? { get }
  
    /// login with the email and password you use on the portal website and get back an auth_token
    func authenticate(request: Protos_AuthenticationRequest, context: StatusOnlyCallContext) -&gt; EventLoopFuture&lt;Protos_AuthenticationResponse&gt;
  
    /// get the collection of devices associated to your partner account, 
    /// optionally limited to devices related to one or more customer emails
    func getDevices(request: Protos_DeviceInventoryRequest, context: StatusOnlyCallContext) -&gt; EventLoopFuture&lt;Protos_DeviceInventoryResponse&gt;
  
    /// get usage data for one or more devices
    func getUsageData(request: Protos_DeviceUsageRequest, context: StatusOnlyCallContext) -&gt; EventLoopFuture&lt;Protos_DeviceUsageResponse&gt;
  
    /// determine if one or more Outlets are currently on
    func getOutletStatus(request: Protos_DeviceListRequest, context: StatusOnlyCallContext) -&gt; EventLoopFuture&lt;Protos_OutletStatusResponse&gt;
  
    /// set one or more Outlets to be on or off.  
    /// only the outlets that were changed will be included in the OutletStatusResponse; outlets that
    /// aren't connected to the cloud or were already in the requested state won't be included
    func setOutletStatus(request: Protos_OutletStatusRequest, context: StatusOnlyCallContext) -&gt; EventLoopFuture&lt;Protos_OutletStatusResponse&gt;
  }
  
  extension Protos_PartnerApiProvider {
    internal var serviceName: Substring { return &quot;protos.PartnerApi&quot; }
  
    /// Determines, calls and returns the appropriate request handler, depending on the request's method.
    /// Returns nil for methods not handled by this service.
    internal func handle(
      method name: Substring,
      context: CallHandlerContext
    ) -&gt; GRPCServerHandlerProtocol? {
      switch name {
      case &quot;Authenticate&quot;:
        return UnaryServerHandler(
          context: context,
          requestDeserializer: ProtobufDeserializer&lt;Protos_AuthenticationRequest&gt;(),
          responseSerializer: ProtobufSerializer&lt;Protos_AuthenticationResponse&gt;(),
          interceptors: self.interceptors?.makeAuthenticateInterceptors() ?? [],
          userFunction: self.authenticate(request:context:)
        )
  
      case &quot;GetDevices&quot;:
        return UnaryServerHandler(
          context: context,
          requestDeserializer: ProtobufDeserializer&lt;Protos_DeviceInventoryRequest&gt;(),
          responseSerializer: ProtobufSerializer&lt;Protos_DeviceInventoryResponse&gt;(),
          interceptors: self.interceptors?.makeGetDevicesInterceptors() ?? [],
          userFunction: self.getDevices(request:context:)
        )
  
      case &quot;GetUsageData&quot;:
        return UnaryServerHandler(
          context: context,
          requestDeserializer: ProtobufDeserializer&lt;Protos_DeviceUsageRequest&gt;(),
          responseSerializer: ProtobufSerializer&lt;Protos_DeviceUsageResponse&gt;(),
          interceptors: self.interceptors?.makeGetUsageDataInterceptors() ?? [],
          userFunction: self.getUsageData(request:context:)
        )
  
      case &quot;GetOutletStatus&quot;:
        return UnaryServerHandler(
          context: context,
          requestDeserializer: ProtobufDeserializer&lt;Protos_DeviceListRequest&gt;(),
          responseSerializer: ProtobufSerializer&lt;Protos_OutletStatusResponse&gt;(),
          interceptors: self.interceptors?.makeGetOutletStatusInterceptors() ?? [],
          userFunction: self.getOutletStatus(request:context:)
        )
  
      case &quot;SetOutletStatus&quot;:
        return UnaryServerHandler(
          context: context,
          requestDeserializer: ProtobufDeserializer&lt;Protos_OutletStatusRequest&gt;(),
          responseSerializer: ProtobufSerializer&lt;Protos_OutletStatusResponse&gt;(),
          interceptors: self.interceptors?.makeSetOutletStatusInterceptors() ?? [],
          userFunction: self.setOutletStatus(request:context:)
        )
  
      default:
        return nil
      }
    }
  }
  
  internal protocol Protos_PartnerApiServerInterceptorFactoryProtocol {
  
    /// - Returns: Interceptors to use when handling 'authenticate'.
    ///   Defaults to calling `self.makeInterceptors()`.
    func makeAuthenticateInterceptors() -&gt; [ServerInterceptor&lt;Protos_AuthenticationRequest, Protos_AuthenticationResponse&gt;]
  
    /// - Returns: Interceptors to use when handling 'getDevices'.
    ///   Defaults to calling `self.makeInterceptors()`.
    func makeGetDevicesInterceptors() -&gt; [ServerInterceptor&lt;Protos_DeviceInventoryRequest, Protos_DeviceInventoryResponse&gt;]
  
    /// - Returns: Interceptors to use when handling 'getUsageData'.
    ///   Defaults to calling `self.makeInterceptors()`.
    func makeGetUsageDataInterceptors() -&gt; [ServerInterceptor&lt;Protos_DeviceUsageRequest, Protos_DeviceUsageResponse&gt;]
  
    /// - Returns: Interceptors to use when handling 'getOutletStatus'.
    ///   Defaults to calling `self.makeInterceptors()`.
    func makeGetOutletStatusInterceptors() -&gt; [ServerInterceptor&lt;Protos_DeviceListRequest, Protos_OutletStatusResponse&gt;]
  
    /// - Returns: Interceptors to use when handling 'setOutletStatus'.
    ///   Defaults to calling `self.makeInterceptors()`.
    func makeSetOutletStatusInterceptors() -&gt; [ServerInterceptor&lt;Protos_OutletStatusRequest, Protos_OutletStatusResponse&gt;]
  }
  
  </code></pre>