> This page is for Applications Protection.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.humansecurity.com/llms.txt.

# Integration with gRPC [BETA]

#### v2.x

The SDK can be integrated into [gRPC](https://grpc.io/) projects.

## Start the SDK

The automatic interceptor is not supported in gRPC, so you should disable requests interception by setting the `PXPolicy/requestsInterceptedAutomaticallyEnabled` to `false`.

```swift
PXPolicy.requestsInterceptedAutomaticallyEnabled = false

// call the start function...

let policy = PXPolicy()
policy.requestsInterceptedAutomaticallyEnabled = false

// call the setPolicy function...
```

## Adding SDK's HTTP headers to your gRPC requests

In order to include the SDK's HTTP headers in your gRPC requests, you should add them to your request's metadata.

```swift
let headers = PerimeterX.headersForURLRequest(forAppId: nil)
var callOption = CallOptions()
for (key, value) in headers {
	callOption.customMetadata.replaceOrAdd(name: key, value: value)
}
// send you gRPC request with `callOption`...
```

Now, use the `call option` instance when you call your send your gRPC request.

## Handle block responses from your server

After receiving an error in the server's response, the gRPC library will throw an exception. pass the information to SDK with the `handleResponse` function.

```swift
do {
	// send your gRPC request...
} catch {
	if let statusError = error as? GRPC.GRPCStatus, let data = statusError.message?.data(using: .utf8) {
		let response = HTTPURLResponse(url: URL(string: "https://your.server.domain")!, statusCode: 403, httpVersion: nil, headerFields: nil)!
		PerimeterX.handleResponse(forAppId: nil, data: data, response: response)
	}
}
```