Skip to main content

iOS

URLSession

If you're using the native URLSession for HTTP requests, you can easily integrate Gateway by modifying your base URL and adding the Gateway API key to your requests.

let baseURL = URL(string: "https://api.meetgateway.com/v1/proxy/YOUR_ENDPOINT/")!
let apiKey = "YOUR_GATEWAY_API_KEY"

// Create a URLRequest
var request = URLRequest(url: baseURL.appendingPathComponent("your-endpoint"))
request.httpMethod = "GET"
request.setValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")

// Make the request
let task = URLSession.shared.dataTask(with: request) { data, response, error in
// Handle response
}
task.resume()

Alamofire

If you're using Alamofire, you can create a custom Session with an interceptor to automatically add the Gateway API key to all requests:

import Alamofire

let baseURL = "https://api.meetgateway.com/v1/proxy/YOUR_ENDPOINT/"
let apiKey = "YOUR_GATEWAY_API_KEY"

// Create an interceptor to add the API key
let interceptor = Interceptor { request, session, completion in
var modifiedRequest = request
modifiedRequest.headers.add(name: "Authorization", value: "Bearer \(apiKey)")
completion(.success(modifiedRequest))
}

// Create a session with the interceptor
let session = Session(interceptor: interceptor)

// Make requests
session.request("\(baseURL)your-endpoint")
.response { response in
// Handle response
}
tip

Make sure to:

  1. Replace YOUR_GATEWAY_API_KEY with your actual Gateway API key
  2. Replace YOUR_ENDPOINT with your target API endpoint
  3. Add any necessary path segments after the base URL in your API calls