https://github.com/nikolainobadi/swiftrestkit
Lightweight Swift package for building type-safe RESTful URLRequest objects with headers, query params, and JSON body support.
https://github.com/nikolainobadi/swiftrestkit
json rest-api swift swift-package urlrequest
Last synced: 23 days ago
JSON representation
Lightweight Swift package for building type-safe RESTful URLRequest objects with headers, query params, and JSON body support.
- Host: GitHub
- URL: https://github.com/nikolainobadi/swiftrestkit
- Owner: nikolainobadi
- License: mit
- Created: 2025-05-12T02:50:31.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-05-12T19:20:04.000Z (5 months ago)
- Last Synced: 2025-06-28T09:12:15.162Z (3 months ago)
- Topics: json, rest-api, swift, swift-package, urlrequest
- Language: Swift
- Homepage:
- Size: 8.79 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwiftRESTKit

[]()
## Overview
**SwiftRESTKit** is a lightweight Swift package for building type-safe `URLRequest` objects using a composable and testable API. It simplifies RESTful request construction for GET, DELETE, POST, PUT, and PATCH operations, with support for custom headers, query parameters, and JSON body encoding.
## Features
- Build RESTful `URLRequest`s with ease
- Strongly-typed header support (`Accept`, `Content-Type`, `Authorization`, and custom)
- Support for query parameters, JSON-encoded bodies, timeout intervals, and cache policies## Installation
To use **SwiftRESTKit** in your SwiftPM project, add the following to your `Package.swift`:
```swift
.package(url: "https://github.com/nikolainobadi/SwiftRESTKit", from: "1.0.0")
```Then add `"SwiftRESTKit"` as a dependency to your target:
```swift
.product(name: "SwiftRESTKit", package: "SwiftRESTKit")
```## Usage
### Build a GET request:
```swift
let request = try RestRequestBuilder.buildGET(
baseURL: URL(string: "https://example.com")!,
path: "search",
query: ["q": "Swift"],
headers: HTTPRequestHeaders(authorization: "Bearer token")
)
```### Build a POST request with JSON body:
```swift
let request = try RestRequestBuilder.buildWrite(
baseURL: URL(string: "https://example.com")!,
path: "users",
method: .post,
body: ["name": "Jane Doe"],
headers: HTTPRequestHeaders(contentType: .json)
)
```## Architecture Notes
The core logic is encapsulated in:
- `RestRequestBuilder`: Public API for request construction
- `HTTPRequestHeaders`: Struct to encapsulate standard and custom headers
- `HTTPWriteMethod`: Enum for POST, PUT, and PATCH
- `RequestBuilderError`: Custom error enum for URL formation issuesPrivate helpers are used internally to ensure testability and reusability of components.
## About This Project
SwiftRESTKit was created as part of a personal effort to review REST fundamentals before starting a new engineering apprenticeship. It helped reinforce practical concepts like request construction, HTTP methods, and header management while building a reusable, testable foundation for future networking work.
The project emphasizes readability, modularity, and Swift-native design patterns.
## Contributing
Contributions are welcome! Please open an issue or submit a pull request on [GitHub](https://github.com/nikolainobadi/SwiftRESTKit).
## License
This project is licensed under the MIT License. See [LICENSE](https://github.com/nikolainobadi/SwiftRESTKit/blob/main/LICENSE) for details.