Client
public final class Client
Client
represents a HTTP client for a FaunaDB server. It provides
methods, such as query
and query(batch:)
that you can use to execute
queries in your server.
Note
This class is meant to be reused as much as possible. If you need to connect to the same server but using a different key’s secret, usenewSessionClient
method instead of creating a new Client
instance.
-
Declaration
Swift
public init(secret: String, endpoint: URL = defaultEndpoint, session: URLSession? = nil)
Parameters
secret
The key’s secret to be used to authenticate requests.
endpoint
The URL address of your FaunaDB server. Default: https://db.fauna.com.
session
The
URLSession
object to be used while performing HTTP requests to FaunaDB. Default:URLSession(configuration: URLSessionConfiguration.default)
. -
Returns a new
Client
instance for the same FaunaDB server but using a different key’s secret to authenticate HTTP requests. The new client shares its parent’s resources, such as its URLSession.Declaration
Swift
public func newSessionClient(secret: String) -> Client
Parameters
secret
The key’s secret to be used to authenticate HTTP requests.
-
Sends a query to the FaunaDB server. All queries are executed asynchronously.
QueryResult
will be fulfilled once the query finishes to run, or fail.Declaration
Swift
public func query(_ expr: Expr) -> QueryResult<Value>
Parameters
expr
The query expression to be sent. Check
FaunaDB.Expr
for more information. -
Sends a batch of queries to the FaunaDB server. All queries are executed asynchronously.
QueryResult
will be fulfilled once all queries finishes to run, or fail. The result array will be in the same order as the request array.Declaration
Swift
public func query(batch: [Expr]) -> QueryResult<[Value]>
Parameters
batch
A sequence of query expressions to be sent to FaunaDB.