https://github.com/grdsdev/swift-http
The HTTP package provides a Swift interface for making HTTP requests and processing responses.
https://github.com/grdsdev/swift-http
Last synced: 4 months ago
JSON representation
The HTTP package provides a Swift interface for making HTTP requests and processing responses.
- Host: GitHub
- URL: https://github.com/grdsdev/swift-http
- Owner: grdsdev
- License: mit
- Archived: true
- Created: 2024-10-21T09:18:27.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-05T17:45:08.000Z (11 months ago)
- Last Synced: 2025-08-13T08:52:40.399Z (8 months ago)
- Language: Swift
- Homepage:
- Size: 76.2 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HTTP
[](https://codecov.io/gh/grdsdev/swift-http)
The `HTTP` package provides a Swift interface for making HTTP requests and
processing responses. It is designed to be simple and intuitive, allowing developers to easily integrate HTTP functionality into their Swift applications.
## Features
- Simple and intuitive API for making HTTP requests
- Support for various HTTP methods (GET, POST, PUT, DELETE, etc.)
- Flexible request options, including custom headers and body
- Asynchronous operations using Swift's async/await
- Built-in support for JSON encoding and decoding
- Multipart form data support
- URL search parameters handling
- Support for streamed responses
## Installation
To integrate the `HTTP` package into your Swift project, add the following line to your `Package.swift` file:
```swift
.package(url: "https://github.com/grdsdev/swift-http.git", from: "0.0.1")
```
Then, include "HTTP" in your target dependencies:
```swift
.target(
name: "YourTargetName",
dependencies: [
.product(name: "HTTP", package: "swift-http"),
.product(name: "HTTPFoundation", package: "swift-http"),
]
)
```
## Usage
### Basic GET Request
```swift
import HTTP
import HTTPFoundation
let response = try await http.get("https://api.example.com/data")
let json = try await response.json()
```
### POST Request with JSON Body
```swift
import HTTP
import HTTPFoundation
let response = try await http.post(
"https://api.example.com/users",
body: ["name": "John Doe", "age": 30]
)
```
### Multipart Form Data
```swift
import HTTP
import HTTPFoundation
var formData = FormData()
formData.append("username", "johndoe")
formData.append("avatar", imageData, filename: "avatar.jpg", contentType: "image/jpeg")
let response = try await http.post(
"https://api.example.com/upload",
body: formData
)
```
### URL Search Parameters
```swift
import HTTP
var params = URLSearchParams("https://example.com?foo=1&bar=2")
params.append("baz", "3")
print(params.description) // Output: foo=1&bar=2&baz=3
```
### Streamed Responses
```swift
import HTTP
import HTTPFoundation
let response = try await http.get("https://api.example.com/stream")
for await chunk in response.body {
// handle chunk of Data
}
```
# API Reference
For detailed API documentation, please refer to the inline comments in the
source code.
## Requirements
- Swift 5.9+
- macOS 10.15+ or iOS 13.0+
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
for details.
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.