GithubHelp home page GithubHelp logo

get's Introduction

get's People

Contributors

andrewsb avatar baekteun avatar briancordanyoung avatar command-tab avatar corysullivan avatar devyeom avatar fonkadelic avatar jnouwen avatar jordanekay avatar kean avatar larsjk avatar lepips avatar liamnichols avatar mariano avatar mbarnach avatar nryrk avatar pavelk avatar pomanks avatar simorgh3196 avatar soemarko avatar theisegeberg avatar vox-humana avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

get's Issues

Problem with sending post requests

Hey, I have a problem with the API client. I can't send requests with a post budy if one of the values is a boolean. Am I doing something wrong?
Bildschirm­foto 2023-03-03 um 00 04 11

Duplicating requests with different body

Hi. I want to make multiple requests whose parameters are identical except for their body.
Since requests can be created only by the factory methods, I have to write code like this to duplicate requests.
Is there a better way to handle this case?

func duplicate<Response: Decodable, Body: Encodable>(request: Request<Response>, body: Body) -> Request<Response> {
        switch request.method {
    case "post":
        return .post(request.path, query: request.query, body: body, headers: request.headers)
    case "put":
        return .put(request.path, query: request.query, body: body, headers: request.headers)
    case "delete":
        return .delete(request.path, query: request.query, body: body, headers: request.headers)
    default:
        return .get(request.path)
    }
}

baseURL incorrect

let baseURL = URL(string: "https://gitlab.com/api/v4")
URL(string: "/test", relativeTo: baseURL)?.absoluteString

expect
https://gitlab.com/api/v4/test

result
https://gitlab.com/test

2022-07-14 05 19 14

73476a8

Protocol for APIClient Methods

I'm remaking our new API with CreateAPI and you've left generous comment in our thread jellyfin/jellyfin-sdk-swift#5. Instead of directly using APIClient, I'm making a wrapper JellyfinClient actor that handles the APIClientDelegate creation to inject required headers for the Jellyfin server, among other things for convenience.

Working with this wrapper would just manually require re-declaring the main APIClient interface methods however can cause issues in the future over the evolution of the package. Would creating a protocol for these methods be appropriate for easier implementation of wrappers?

Concurrency warning

Hello 👋🏻

After switching the compiler option Strict Concurrency Checking to Complete, I received the warning below:

⚠️ Non-sendable type '(inout APIClient.Configuration) -> Void' passed in call to nonisolated initializer 'init(baseURL:_:)' cannot cross actor boundary.

Screen Shot 2022-08-29 at 14 10 20

Just informing, I don't know how important it is.
Xcode 14.0 beta 5 | Get 1.0.1

SwiftUI Example

Please make a small example of an application using SwiftUI & Get.
Or can someone share a gist?

APIClient v2

I'm considering redesigning the APIClient public API for Get 1.0. It was initially designed to accommodate only the most basic scenarios, but I'd like it to be more flexible. Here is a draft of a new API.

public protocol APIClient2 {
    // No changes in these APIs, except for removal of magic `Response<Data>` and `Response<String>` support (see p3)
    func send<T: Decodable>(_ request: Request<T>) async throws -> Response<T>
    func send<T: Decodable>(_ request: Request<T?>) async throws -> Response<T?>
    @discardableResult func send(_ request: Request<Void>) async throws -> Response<Void>

    // Getting decoded response for `URL`/`URLRequest`
    func value<T: Decodable>(_ type: T.Type, for url: URL) async throws -> Response<T>
    func value<T: Decodable>(_ type: T.Type, for urlRequest: URLRequest) async throws -> Response<T>

    // Getting raw response `Data` (no decoding)
    func data(for url: URL) async throws -> Response<Data>
    func data(for urlRequest: URLRequest) async throws -> Response<Data>
    func data<T>(for request: Request<T>) async throws -> Response<Data>

    // Getting response `String` (no decoding except for .utf8 decoding)
    func string(for url: URL) async throws -> Response<String>
    func string(for urlRequest: URLRequest) async throws -> Response<String>
    func string<T>(for request: Request<T>) async throws -> Response<String>

    // (?) Add `URLSessionDataDelegate` to all APIs too for pogress reporting, etc.
    func response<T: Decodable>(for request: Request<T>, delegate: URLSessionDataDelegate) async throws -> Response<T>
}

Main Changes

  1. You can now use URL and URLRequest in addition to Request
  2. Pass URLSessionDataDelegate for progress reporting, per-task auth, etc.
  3. Remove magic Response<Data> and Response<String> support from send(_:). If you use send(_:), they'll just use the default Decodable implementation for these types. You'll need to call data(for:) or string(for:) instead – faster, more discoverable, self-documenting

APIClientDelegate functions not called?

Hi!

I'm trying to get Get to work in my current project, and have created a small struct implementing a simple call to our backend. I need to set a token in the header for each call, so I have implemented a APIClientDelegate like this: (more or less a copy of the sample in the readme)

 final class AuthorizingDelegate: APIClientDelegate {
    func client(_ client: APIClient, willSendRequest request: inout URLRequest) async throws {
        print("-- client:willSendRequest")
        request.allHTTPHeaderFields = ["Authorization": "Bearer \(await getToken())"]
    }

    func shouldClientRetry(_ client: APIClient, withError error: Error) async throws -> Bool {
        print("-- client:withError")
        if case .unacceptableStatusCode(let statusCode) = (error as? APIError), statusCode == 401 {
            return await !getToken().isEmpty
        }
        return false
    }

    func client(_ client: APIClient, didReceiveInvalidResponse response: HTTPURLResponse, data: Data) -> Error {
        print("-- client:didReceiveInvalidResponse:data")
        return APIError.unacceptableStatusCode(response.statusCode)
    }

    func getToken() async -> String {
        await withUnsafeContinuation { continuation in
            Auth.auth().currentUser?.getIDToken(completion: { token, error in
                continuation.resume(returning: token ?? "")
            })
        }
    }
}

The request I'm testing looks like this:

struct ReqTest {
    let delegate = AuthorizingDelegate()
    func testMe() async -> String {
        let client = APIClient(host: "xxxxxx.xxxx") {
            $0.sessionConfiguration.requestCachePolicy = .reloadIgnoringLocalCacheData
            $0.delegate = delegate
        }
        do {
            let req = Request<MyResponse>.get("/api/user")
            let resp = try await client.send(req).value
            return resp.nickname
        } catch {
            print(error)
            return error.localizedDescription
        }
    }
}

When calling testMe(), this us what is logged:

-- client:didReceiveInvalidResponse:data
unacceptableStatusCode(401)
Response status code was unacceptable: 401.

I would expect to see a call to the other delegate functions to get the neccessary token, but this is not the case. Any clue?

localhost:yourPort/yourname/v1/yourEndpoint - A server with the specified hostname could not be found.

Working url from Postman:
http://localhost:9009/yourname/v1/endpointName

Paths are generated automatically from OpenApi via CreateAPI and looks like that: /v1/endpointName

Client host: APIClient(host: "localhost:9009/yourname")
or: APIClient(host: "localhost/yourname")

let client: APIClient = APIClient(host: "localhost:9009/yourname") {
    //$0.port = 9009
    $0.isInsecure = true
    $0.delegate = YourDelegate()
}

Generated via Get package method makeURL(path: String, query: [(String, String?)]?) throws -> URL:
http://localhost%3A9009%2Fyourname/v1/endpointName

Output error:
NSLocalizedDescription=A server with the specified hostname could not be found., NSErrorFailingURLStringKey=http://localhost%3a9009%2fyourname/v1/endpointName?, NSErrorFailingURLKey=http://localhost%3a9009%2fyourname/v1/endpointName?, _kCFStreamErrorDomainKey=12}

Some methods of custom URLSessionDelegate are ignored by APIClient

It is handy we can set our own custom URLSessionDelegate in APIClient init.

        self.api = APIClient(baseURL: baseURL, {
            $0.sessionDelegate = ...
        })

But custom delegate methods are just not called for simple GET/POST queries. Don't think this how it should be. It looks like DataLoader.swift just lacks them.

Particularly in my case (I need to do some SSl pinning) if I add the following code to DataLoader.swift everything begins to work as expected:

    func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        userSessionDelegate?.urlSession?(session, didReceive: challenge, completionHandler: completionHandler) ??
        completionHandler(.performDefaultHandling, nil)
    }

It looks like delegation is forwarded only for some subtypes of URLSessionDelegate (URLSessionTaskDelegate, URLSessionDataDelegate, URLSessionDownloadDelegate) but not for the type itself. Just not sure if it will be correct to implement such forwarding for both URLSessionDelegate and it subtypes. That's why made it an issue, not a pull request.

_testGitHubUserApi() only passes with passes with "lean" user

If I try to lookup a different api.github.com/users/briviere the test fails with the following within the APIClient.Serializer.decode actor:

test case:

final class APIClientIntegrationTests: XCTestCase {
var sut: APIClient!

override func setUp() {
    super.setUp()
    
    sut = APIClient(host: "api.github.com")
}

func testGitHubUsersApi() async throws {
    let user = try await sut.send(Resources.users("briviere").get)
    
    print(user)
    
    XCTAssertEqual(user.login, "briviere")
}

}

Exception:

Printing description of data:
▿ 1282 bytes

  • count : 1282
    ▿ pointer : 0x00007f781283e200
    • pointerValue : 140153683436032
      Printing description of self:
      <Serializer: 0x600001e38af0>
      2021-11-27 10:17:08.571713-0500 xctest[77569:5961128] NSInvalidUnarchiveOperationException attempting to serialize associated error of issue: This decoder will only decode classes that adopt NSSecureCoding. Class '__SwiftValue' does not adopt it.
      :0: error: -[APIClientTests.APIClientIntegrationTests testGitHubUsersApi] : failed: caught error: "The data couldn’t be read because it is missing."
      Test Case '-[APIClientTests.APIClientIntegrationTests testGitHubUsersApi]' failed (106.243 seconds).
      Test Suite 'APIClientIntegrationTests' failed at 2021-11-27 10:17:08.573.
      Executed 1 test, with 1 failure (1 unexpected) in 106.243 (106.244) seconds
      Test Suite 'APIClientTests.xctest' failed at 2021-11-27 10:17:08.574.
      Executed 1 test, with 1 failure (1 unexpected) in 106.243 (106.245) seconds
      Test Suite 'Selected tests' failed at 2021-11-27 10:17:08.574.
      Executed 1 test, with 1 failure (1 unexpected) in 106.243 (106.247) seconds
      Program ended with exit code: 1

How to handle 422 json error response?

Our api server gives a 422 response when validating request params:

{
    "errors": [{ "detail": "Missing field: anon_id" }]
}

However, Get only supplies the error code: Response status code was unacceptable: 422 via APIError

.unacceptableStatusCode(let statusCode)

How can we hook into the actual error response for logging and (sometimes) showing to the user?

Add `MultiAPIClientDelegate`, a delegate that forwards calls to multiple underlying delegates.

Hi @kean hope you're doing great, first thanks for this awesome library, I'm using it on a lot of my projects.

And one thing I find myself always implementing is this MultiAPIClientDelegate.

An APIClientDelegate implementation that forwards calls to multiple underlying delegates, below is the implementation I use.

if you find this useful for adding to the library, I can PR it.

/// An ``APIClientDelegate`` that forward calls to multiple delegates in order.
public struct MultiAPIClientDelegate: APIClientDelegate {
    let delegates: [APIClientDelegate]

    public init(_ delegates: [APIClientDelegate]) {
        self.delegates = delegates
    }

    public func client(_ client: APIClient, willSendRequest request: inout URLRequest) async throws {
        for delegate in delegates {
            try await delegate.client(client, willSendRequest: &request)
        }
    }

    public func client(_ client: APIClient, shouldRetry task: URLSessionTask, error: Error, attempts: Int) async throws -> Bool {
        for delegate in delegates {
            if try await delegate.client(client, shouldRetry: task, error: error, attempts: attempts) {
                return true
            }
        }
        return false
    }

    public func client(_ client: APIClient, validateResponse response: HTTPURLResponse, data: Data, task: URLSessionTask) throws {
        for delegate in delegates {
            try delegate.client(client, validateResponse: response, data: data, task: task)
        }
    }

    public func client<T>(_ client: APIClient, makeURLForRequest request: Request<T>) throws -> URL? {
        for delegate in delegates {
            if let url = try delegate.client(client, makeURLForRequest: request) {
                return url
            }
        }
        return nil
    }

    public func client<T>(_ client: APIClient, encoderForRequest request: Request<T>) -> JSONEncoder? {
        for delegate in delegates {
            if let encoder = delegate.client(client, encoderForRequest: request) {
                return encoder
            }
        }
        return nil
    }

    public func client<T>(_ client: APIClient, decoderForRequest request: Request<T>) -> JSONDecoder? {
        for delegate in delegates {
            if let decoder = delegate.client(client, decoderForRequest: request) {
                return decoder
            }
        }
        return nil
    }
}

OAuth functionality doesn't retry because a 401/403 doesn't throw an error

Line #43 of APIClient has this:

    public func send(_ request: URLRequest) async throws -> (Data, URLResponse) {
        do {
            return try await actuallySend(request)
        } catch {
            guard await delegate.shouldClientRetry(self, withError: error) else { throw error }
            return try await actuallySend(request)
        }
    }

Perhaps I'm mistaken, but a 401/403 doesn't actually throw an error here, it'll just continue a normal right? The shouldClientRetry would only be called if the network had some actually throwing error here, right?

I usually approach OAuth in a completely different way, and if you agree I'd love to submit a PR with a different approach where auth'ed endpoints are wrapped at the call site, rather than handled inside of the API framework.

How to globally set a common group of header

Background:

The current situation is I have to assign headers to Request for each API request while my expectation is to set that globally.

For example, I have a base header required to send to the backend for any request. Ideally, there's a method I can use like

APIClient.setCommonHeader(headers)

Here is my code

import Foundation
import Get

struct LeisureAPIClient {
    static func getUser() async throws -> [User] {
        let config = LeisureAPI.users
        return try await APIClient(baseURL:config.baseURL) {
            $0.delegate = LeisureAPIClientDelegate.shared
        }.send(Request(path: config.path, headers: ["example"])).value 
    }
}

public enum LeisureAPI {
    case users
    case topContributors
}

extension LeisureAPI: TargetType {
    
    var baseURL: URL {
        return URL(string: "https://api.github.com")!
    }
    
    var path: String {
        switch self {
        case .users:
            return "/users"
        case .topContributors:
            return "/repos/scala/scala/contributors"
        }
    }
    
    var method: HttpMethod {
        return .get
    }
    
    
    var headers: [String : String]? {
        return nil
    }
}


enum HttpMethod: String {
    case post = "post"
    case get = "get"
}

protocol TargetType {

    /// The target's base `URL`.
    var baseURL: URL { get }

    /// The path to be appended to `baseURL` to form the full `URL`.
    var path: String { get }

    /// The HTTP method used in the request.
    var method: HttpMethod { get }

    /// Provides stub data for use in testing. Default is `Data()`.
    var sampleData: Data? { get }

    /// The headers to be used in the request.
    var headers: [String: String]? { get }
}

extension TargetType {
    var sampleData: Data? {
        return nil
    }
    
    var headers: [String: String]? {
        baseHeader
    }
    
    var baseHeader: [String: String] {
        [
            "Authorization": "allow",
            "userType": "xxx",
            "type": "iOS",
            "x-api-key": "xxxx",
            "device_id": "xxxx",
            "token": "xxxx",
            "uid": "xxxx"
        ]
    }
}


final class LeisureAPIClientDelegate: APIClientDelegate {
    static var shared = LeisureAPIClientDelegate()
    func client(_ client: APIClient, validateResponse response: HTTPURLResponse, data: Data, task: URLSessionTask) throws {
        if response.statusCode == 304 {
            print("304 returned")
            NotificationCenter.default.post(name: Notification.Name("EXPIRED"), object: nil)
        } else {
            print("validateResponse")
        }
    }
}

multipart/form-data integration?

I didn't see an example of how to do this, i'm using MultipartFormDataKit & what i'm doing is

return Future {
    let filename = UUID().uuidString
    let boundary = RandomBoundaryGenerator.generate()
    let multipartFormData = try MultipartFormDataKit.MultipartFormData.Builder.build(
        with: [(
            name: "file",
            filename: "\(filename).png",
            mimeType: MIMEType.imagePng,
            data: data
        )],
        willSeparateBy: boundary
    ).body

    return try await self.apiStore.send(Paths.me.picture.patch(multipartFormData), configure: {
        $0.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
    }).value
}

but it feels a little verbose at the callsite. my swagger definition says that the form should contain data at the key file, for example

is this the expected integration? or is there something a little less verbose?

AnyEncodable

I want to know why use AnyEncodable in encoder

Suggestion - adding the URLRequest to the delegate method shouldClientRetry

In the signature of the delegate method
func shouldClientRetry(_ client: APIClient, withError error: Error) async throws -> Bool
might be useful to add URLRequest.

This could be useful for handling situations where multiple requests fail.

Or can you please show an example or hint how you handle this situation?

CocoaPods support

We're building an iOS framework that primarily supports SPM, but we know there are some adopters that still use CocoaPods. Could this library support CocoaPods as well?

Add urlSession(_:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:) to DataLoader's implemented delegate callbacks

Would it be possible to add urlSession(_:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:) to DataLoader's list of implemented URLSessionTaskDelegate callbacks?

I'm not using one of APIClient's upload(...) functions where I could just set the delegate directly because those functions don't do multipart form requests (unless I'm missing something?) and thus can't get at the uploaded file on my PHP server side, so I instead implemented them "manually" with send(..) by modifying the inout URLRequest directly. Unfortunately, since DataLoader doesn't have the requested callback implemented, I can't monitor the progress of the data send.

I was just going to add it in an extension, but DataLoader isn't exposed outside the package.

Encode '+' in query string

Hello @kean. Thank you for this library, I really admire the elegant API you achieved with this.

I've been using Get in a side project and stumbled into an issue where an explicitly written + character was not encoded when used in a query string (e.g. domain.tld?query=value1+value2). This resulted in an unexpected response from the API i was using.

According to a note in this Apple Doc which also refers to RFC 3986 and W3C, the + sign is a valid character for representing a space in a query string. Due to this fact it seems, the character is not automatically encoded when reading the url from a URLComponents instance. The same note suggests to preemptively encode the + character as well if needed.

I think it would be reasonable to add this behavior to Get, what are your thoughts?

I made a sample implementation in a fork here. Heavily inspired by Alamofire.

send(_:) method always tries to decode empty response since newest version

Hi 👋🏻

When declaring a method with an optional response body (see example), the call only results in a decoding error because the method tries to decode an empty response.

Optional response body method:

func getWatching(slug: String, extended info: ExtendedInfo?) async throws -> Response<Users.GetWatching.Response?>

Error:

dataCorrupted(Swift.DecodingError.Context(
    codingPath: [], 
    debugDescription: "The given data was not valid JSON.", 
    underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "Unable to parse empty data." UserInfo={NSDebugDescription=Unable to parse empty data.})
    )
)

The same code worked in previous version though (it simply returned nil).

Conforming to `Codable`

Hi Alex 🤝
Is it possible to conform a struct Response to Codable?

My data model conforms to Codable and has a Response<String> property.
I implemented a func encode(to encoder: Encoder) throws { and init(from decoder: Decoder) throws { but I'm getting an error:

let response: URLResponse does not conform to Codable.

I understand what this error means.

can't get this to build to xcframeworks

brew install mint
mint install unsignedapps/swift-create-xcframework
swift create-xcframework --platform ios


ft:359:11: error: 'value' is only available in iOS 15.0 or newer
        }.value
          ^
/Users/johndpope/Documents/gitWorkspace/Supabase/Sources/Get/Sources/Get/DataLoader.swift:359:11: note: add 'if #available' version check
        }.value
          ^
/Users/johndpope/Documents/gitWorkspace/Supabase/Sources/Get/Sources/Get/DataLoader.swift:348:6: note: add @available attribute to enclosing global function
func decode<T: Decodable>(_ data: Data, using decoder: JSONDecoder) async throws -> T {
     ^

** ARCHIVE FAILED **


The following build commands failed:
	CompileSwift normal arm64 (in target 'Get' from project 'Get')
	CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler (in target 'Get' from project 'Get')
(2 failures)
Error: xcodebuild exited with a non-zero code: 65

swift-driver version: 1.26.9 Apple Swift version 5.5.1 (swiftlang-1300.0.31.4 clang-1300.0.29.6)
Target: x86_64-apple-macosx12.0

will try updating xcode to latest.

UPDATE

actually even just running
swift build - I get errors - must be my machine.


ate.swift:11:17: note: add @available attribute to enclosing protocol
public protocol APIClientDelegate {
                ^
/Users/johndpope/Documents/gitWorkspace/Supabase/Sources/Get/Sources/Get/APIClientDelegate.swift:63:81: error: concurrency is only available in macOS 12.0.0 or newer
    func client(_ client: APIClient, willSendRequest request: inout URLRequest) async throws {
                                                                                ^
/Users/johndpope/Documents/gitWorkspace/Supabase/Sources/Get/Sources/Get/APIClientDelegate.swift:63:10: note: add @available attribute to enclosing instance method
    func client(_ client: APIClient, willSendRequest request: inout URLRequest) async throws {
         ^
/Users/johndpope/Documents/gitWorkspace/Supabase/Sources/Get/Sources/Get/APIClientDelegate.swift:62:8: note: add @available attribute to enclosing extension
public extension APIClientDelegate {
       ^
/Users/johndpope/Documents/gitWorkspace/Supabase/Sources/Get/Sources/Get/APIClientDelegate.swift:67:101: error: concurrency is only available in macOS 12.0.0 or newer
    func client(_ client: APIClient, shouldRetry task: URLSessionTask, error: Error, attempts: Int) async throws -> Bool {
                                                                                                    ^
/Users/johndpope/Documents/gitWorkspace/Supabase/Sources/Get/Sources/Get/APIClientDelegate.swift:67:10: note: add @available attribute to enclosing instance method
    func client(_ client: APIClient, shouldRetry task: URLSessionTask, error: Error, attempts: Int) async throws -> Bool {
         ^
/Users/johndpope/Documents/gitWorkspace/Supabase/Sources/Get/Sources/Get/APIClientDelegate.swift:62:8: note: add @available attribute to enclosing extension
public extension APIClientDelegate {
       ^

Problem with Pulse

I would like to use Pulse in my App.
I can't use PulseCore.URLSessionProxyDelegate()

This is my code

import Get
import Pulse

let client = APIClient(baseURL: URL(string: "http://localhost")) {
    $0.sessionDelegate = PulseCore.URLSessionProxyDelegate() // Error: Cannot find 'PulseCore' in scope
}

Can you help me?

Error of No such module 'Get'

I tried every possible way to fix the following issue but still not working

  • reset Package caches
  • Resolve package versions
  • Clean build folder
  • Reboot my MacbookPro

Does anyone know the potential root cause.? I'm on Xcode 15.3 with MacOS 14.3.1

image

image

Using HTTP instead of HTTPS

Can I use HTTP instead of HTTPS? If I manually specify http:// it doesn't work and if I don't specify it it uses https.
Code:
@IBAction func backendDetails(_ sender: Any) { let client = APIClient(host: "http://\(hostname):\(port)") Task{ let result = try? await client.send(.get("/STOInfo/STOVersion")).value } }
Result:
2022-04-09 16:11:17.499954+0200 ServiceTOOLS Control[1854:101545] Connection 0: encountered error(12:1) 2022-04-09 16:11:17.500943+0200 ServiceTOOLS Control[1854:101620] Task <758B7F50-2C4C-42E1-8D91-EDF251350051>.<1> HTTP load failed, 0/0 bytes (error code: -1000 [1:22]) 2022-04-09 16:11:17.508481+0200 ServiceTOOLS Control[1854:101620] Task <758B7F50-2C4C-42E1-8D91-EDF251350051>.<1> finished with error [-1000] Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo={_kCFStreamErrorCodeKey=22, NSUnderlyingError=0x2804f12c0 {Error Domain=kCFErrorDomainCFNetwork Code=-1000 "(null)" UserInfo={_kCFStreamErrorCodeKey=22, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <758B7F50-2C4C-42E1-8D91-EDF251350051>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask <758B7F50-2C4C-42E1-8D91-EDF251350051>.<1>" ), NSLocalizedDescription=bad URL, NSErrorFailingURLStringKey=https://http%3a%2f%2f192.168.178.20%3a5704/STOInfo/STOVersion, NSErrorFailingURLKey=https://http%3a%2f%2f192.168.178.20%3a5704/STOInfo/STOVersion, _kCFStreamErrorDomainKey=1}
Result without http:// :
2022-04-09 16:19:26.078668+0200 ServiceTOOLS Control[1912:103890] Connection 3: received failure notification 2022-04-09 16:19:26.078771+0200 ServiceTOOLS Control[1912:103890] Connection 3: failed to connect 12:8, reason -1 2022-04-09 16:19:26.078822+0200 ServiceTOOLS Control[1912:103890] Connection 3: encountered error(12:8) 2022-04-09 16:19:26.080123+0200 ServiceTOOLS Control[1912:103890] Task <E28CB0EE-1963-436A-9334-38F862483B88>.<1> HTTP load failed, 0/0 bytes (error code: -1003 [12:8]) 2022-04-09 16:19:26.084242+0200 ServiceTOOLS Control[1912:103890] Task <E28CB0EE-1963-436A-9334-38F862483B88>.<1> finished with error [-1003] Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo={_kCFStreamErrorCodeKey=8, NSUnderlyingError=0x2836f70c0 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)" UserInfo={_NSURLErrorNWPathKey=satisfied (Path is satisfied), interface: en0, ipv4, dns, _kCFStreamErrorCodeKey=8, _kCFStreamErrorDomainKey=12}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <E28CB0EE-1963-436A-9334-38F862483B88>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask <E28CB0EE-1963-436A-9334-38F862483B88>.<1>" ), NSLocalizedDescription=A server with the specified hostname could not be found., NSErrorFailingURLStringKey=https://192.168.178.20%3a5704/STOInfo/STOVersion, NSErrorFailingURLKey=https://192.168.178.20%3a5704/STOInfo/STOVersion, _kCFStreamErrorDomainKey=12}

[Question] Purpose of `Request`'s `id` property?

👋 I noticed that Request defines the following property:

public var id: String?

But it's not currently used. I'm wondering what the intended purpose of this property was?

For context, for crash reporting/debugging purposes, I want a way to identify which path (endpoint/controller) is being represented by a Request when using CreateAPI to generate those request definitions. Using the actual URL path doesn't cut it, because /repos/1 and /repos/2 are not unique when they are both representing the same endpoint (/repos/{id}).

For that reason, I had considered that maybe CreateAPI could pass the operationId to this property, but I didn't want to open a PR that could make that possible if I misunderstood the purpose of it.

WDYT? Thanks!

GitHubAPI usage returning 401 response

Tired out calling the GitHubAPI usage with updating GitHubAPIClientDelegete with my personal Github token but getting a 401 unauthorized.

try await usage()

I don't think the GitHubAPIClientDelegete is adding the required requests headers.

Brian

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.