Transit API - Swift

Transit API with Swift 🍎

Integrate Transit API into your Swift application.

Installation

This example needs no package: it uses Foundation's URLSession with async/await (Swift 5.7 and later). For iOS apps there is also a native Swift SDK, listed on SDKs.

Example Code

import Foundation

var request = URLRequest(url: URL(string: "https://api.vedika.io/v2/astrology/transits")!)
request.httpMethod = "POST"
request.setValue("Bearer YOUR_API_KEY", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = """
    {
      "datetime": "1990-06-15T10:30:00",
      "latitude": 18.5204,
      "longitude": 73.8567,
      "timezone": "Asia/Kolkata"
    }
    """.data(using: .utf8)

let (data, response) = try await URLSession.shared.data(for: request)
print((response as! HTTPURLResponse).statusCode)
print(String(decoding: data, as: UTF8.self))

Anything compiled into a shipped app can be extracted, including the API key. For consumer apps, call the Vedika API from your own backend and keep the key on the server.

Get Started Free

Try our sandbox API with no authentication required

Try Sandbox Read Docs