Compile a completely typed sdk of your Bridge project with one command.
- TypeScript SDK Generation: Generates a TypeScript SDK with typed API methods
- Swift SDK Generation: Generates a Swift SDK with async/await support and proper error handling
- OpenAPI Specification: Automatically generates OpenAPI documentation
Run the compiler in your Bridge project:
npx bridge-compile
This will automatically generate:
- TypeScript SDK in
./sdk/
directory - Swift SDK as
./sdk.swift
file - OpenAPI documentation as
./openapi.json
You'll only be prompted for your server URL if no configuration file exists.
You can create a bridge.config.json
file to avoid the server URL prompt:
{
"serverUrl": "http://localhost:8080"
}
You can also pass the server URL as a command line argument:
npx bridge-compile http://localhost:8080
The Swift SDK generates a single sdk.swift
file that includes:
- Foundation networking code with async/await support
- Strongly typed request/response models
- Error handling with custom
APIError
type - Support for GET, POST, PUT, PATCH, DELETE methods
- Query parameters, headers, and body support
// Base networking layer
struct APIError: Error { ... }
struct Result<T: Decodable> { ... }
func fetch<R: Decodable>(...) async -> Result<R> { ... }
// Generated API classes
class User {
struct CreateBody: Encodable { ... }
struct CreateResponse: Decodable { ... }
func create(body: CreateBody) async -> Result<CreateResponse> { ... }
}
// Main API entry point
public class API {
let user = User()
}
let api = API()
// Create a user
let result = await api.user.create(body: User.CreateBody(
name: User.CreateBody.Name(first: "John", last: "Doe"),
email: "john@example.com"
))
switch result {
case let (data?, nil):
print("User created: \(data.user.name)")
case let (nil, error?):
print("Error: \(error.name) - \(error.status)")
default:
print("Unknown error")
}