Skip to content

emrahu/sURL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sURL

@emrahusar Swift 6.0 macOS 10.15+

A modern Swift implementation of cURL - make HTTP requests from the command line with ease!

Inspired by cURL, completely rewritten using modern Swift 6 features including async/await, structured concurrency, and Swift Argument Parser.

Features

  • Modern Swift - Built with async/await, actors, and structured concurrency
  • Type-Safe CLI - Uses Swift Argument Parser for robust command-line interface
  • Beautiful Output - Colored terminal output with clean formatting
  • Easy to Use - Intuitive command structure similar to cURL
  • Full HTTP Support - GET, POST, JSON requests with custom headers
  • Concurrent Requests - Built-in support for parallel request processing
  • Error Handling - Comprehensive error reporting and validation

Installation

Requirements

  • Swift 5.9+ (Swift 6.0 recommended)
  • macOS 10.15+
  • Xcode 12+ (for development)

Build from Source

git clone https://github.com/emrahu/sURL.git
cd sURL
swift build -c release

The executable will be available at .build/release/sURL

Add to PATH (Optional)

cp .build/release/sURL /usr/local/bin/

Usage

Basic Commands

Get help for any command:

surl --help
surl get --help
surl json --help

GET Requests

# Simple GET request
surl get https://httpbin.org/get

# Include response headers
surl get --include-headers https://httpbin.org/get

# Verbose output (headers + status info)
surl get --verbose https://httpbin.org/get

# Custom headers
surl get -H "Authorization: Bearer token" -H "User-Agent: MyApp/1.0" https://api.example.com

POST Requests (Form Data)

# POST with form data
surl post --data "name=John&email=john@example.com" https://httpbin.org/post

# POST with custom headers
surl post -H "X-API-Key: secret" --data "key=value" https://api.example.com/submit

JSON Requests

# POST JSON data (equivalent to curl -X POST -H "Content-Type: application/json" -d '{}')
surl json --data '{"name": "John", "age": 30}' https://httpbin.org/post

# JSON with custom headers and verbose output
surl json --verbose -H "Authorization: Bearer token" --data '{"query": "search"}' https://api.example.com/search

Advanced Examples

# GET with multiple custom headers and verbose output
surl get --verbose \
  -H "Accept: application/json" \
  -H "User-Agent: sURL/2.0" \
  https://api.github.com/users/octocat

# JSON POST with authentication
surl json \
  -H "Authorization: Bearer your-token-here" \
  -H "Content-Type: application/json" \
  --data '{"title": "New Post", "content": "Hello World!"}' \
  https://api.example.com/posts

Architecture

sURL is built with modern Swift patterns:

  • Swift Argument Parser - Type-safe command-line argument parsing
  • Async/Await - Modern asynchronous networking
  • Actor-based NetworkManager - Thread-safe request handling
  • Result Types - Robust error handling
  • Protocol-Oriented Design - Clean, modular architecture

Project Structure

Sources/
└── sURLCore/
    ├── sURL.swift           # Main CLI and command definitions
    ├── NetworkManager.swift # Async networking layer
    ├── NetworkTypes.swift   # HTTP types and errors
    ├── OutputFormatter.swift# Console output formatting
    └── ...

🔧 Development

Building

swift build

Testing

swift test

Code Style

The project follows modern Swift conventions:

  • Async/await for asynchronous operations
  • Actor isolation for thread safety
  • Result types for error handling
  • Protocol-oriented design

📋 Command Reference

Command Description Example
get Perform GET request surl get https://example.com
post POST with form data surl post --data "key=value" https://example.com
json POST with JSON data surl json --data '{"key":"value"}' https://example.com

Global Options

Flag Description
-h, --help Show help information
--version Show version
-i, --include-headers Include response headers
-v, --verbose Verbose output
-H, --headers Custom headers (format: 'Key: Value')

Roadmap

  • File upload/download support
  • HTTP authentication methods
  • Cookie handling
  • Proxy support
  • Response caching
  • Configuration files
  • Shell completion scripts

Feedback & Contributions

This project is actively maintained! Contributions and feedback are welcome:

License

sURL is open source and available under the MIT license. See the LICENSE file for more information.

Version History

  • v2.0.0 - Complete rewrite with Swift 6, async/await, and modern architecture
  • v1.0.0 - Initial release with basic functionality

About

Emulating cURL cli in Swift

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages