Swiftpack.co -  lyndseypenman/Networking as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
lyndseypenman/Networking
Very basic networking library
.package(url: "https://github.com/lyndseypenman/Networking.git", from: "0.1.1")

Networking

Extremely basic Combine networking library for personal use.

Initialise a NetworkService with a URLSession and JSONDecoder

To prepare a request, create a RequestData object by specifying:

  • Endpoint
  • HTTPMethod (current provided options are GET, PUT, and POST)
  • headers (if no headers are specified, "Content-Type": "application/json" is added by default. To remove, please specify and empty dictionary)
  • Request body Data where appropriate

To perform a request, pass the RequestData into makeRequest(with requestData: RequestData). This will return an AnyPublisher<T, Error> where T can be any Decodable type.

Example

let networkService: NetworkAPI = NetworkService(session: .shared, decoder: JSONDecoder())

let requestData = RequestData(endpoint: .init(url: URL(string: "https://mocki.io/v1/ddd24ca5-b6fe-480b-9b28-4528fa90fc70")!, 
                              authorisedRequest: false), 
                              httpMethod: .get, 
                              body: nil)
                              
let responsePublisher: AnyPublisher<MyJSON, Error> = networkService.makeRequest(with: requestData)

responsePublisher.sink { _ in
  print("completed")
} receiveValue: { myJSON in
  print("hello: \(myJSON.hello)")
}
.store(in: &cancellables)

GitHub

link
Stars: 0
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API