Skip to content

eonil/swift-sync-http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SyncHTTP

Eonil, 2019.

Build Status

Performs several HTTP calls synchronously in most reliable way.

  • There are small needs for synchronous HTTP calls in Swift.
  • Unfortunately URLSession is asynchronous only.
  • There are several pitfalls to make it synchronous.

This library provide these features.

  • Synchronous HTTP call using URLSession.

  • This does not involve semaphore or lock.

    • Semaphores are likely to cause some subtle issues with URLSession.
    • Based on repeated thread sleeping.
  • Carefully designed and tuned for short-running, CLI programs.

    • Never cached.
    • State-less.
    • Fails faster than default. 10 second timeout.
  • Maybe doesn't work well in other situations.

  • Future proof simple API.

    • Implementation can be replaced for better one later.
    • You don't have to change your code.

Getting Started

Add Swift package.

.package(url: "https://github.com/eonil/swift-sync-http", from: "0.0.3"),

Import.

import SyncHTTP

And use.

let reply = try SyncHTTP.get(address: "https://google.com")
print(reply)

License & Credits

Licensed under "MIT License". Copyright(C) Eonil 2019.

About

Small utility to perform HTTP operations synchronously.

Resources

License

Stars

Watchers

Forks

Packages

No packages published