OpenLibrary

0.0.1

A cross-platform Swift OpenLibrary API client
natikgadzhi/swift-openlibrary

What's New

2024-12-31T04:00:06Z

OpenLibrary

A Swift library for interacting with the OpenLibrary API. This package provides a clean, type-safe interface to search books, fetch book details, and interact with other OpenLibrary endpoints.

Features

  • Cross-platform support (iOS, macOS, Linux) nope, not yet.
  • Type-safe API client
  • Async/await based API
  • Configurable logging compatible with OSLog.Logger
  • Zero external dependencies

Installation

Add this package to your project using Swift Package Manager:

dependencies: [
    .package(url: "https://github.com/natikgadzhi/swift-openlibrary.git", branch: "main")
]

Usage

import OpenLibrary

// Initialize the client, optionally with a logger
let client = OpenLibraryAPI()

// Search for books in the user's system language
// Returns an array of OpenLibraryWork objects
let books = try await client.searchBooks(query: "Foundation Asimov")

// Fetch all editions for a specific work
// Returns an array of OpenLibraryEdition objects
let editions = try await client.getWorkEditions(workKey: "OL45883W")

// With logging enabled (on Apple platforms)
import OSLog
let logger = Logger(subsystem: "com.yourapp", category: "openlibrary")
let clientWithLogging = OpenLibraryAPI(logger: logger)

Logging

The library supports logging through a simple protocol OpenLibraryLoggerProtocol. On Apple platforms, OSLog.Logger is supported out of the box. For other platforms, you can implement the protocol with your preferred logging solution.

License

MIT License. See LICENSE file for details.

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sat May 17 2025 01:49:03 GMT-0900 (Hawaii-Aleutian Daylight Time)