Replies: 2 comments 3 replies
-
Hey @mackoj! Thanks for taking the time to provide so much feedback! It's super helpful. The particular DSL limitation you mention will be something we should be able to overcome in Swift 5.7. We unfortunately can't enable an experimental flag in the library to work around the issue in the meantime (and we think that the library putting URL Routing to use would need to be the one enabling experimental flags if any were available to fix the issue). It is also possible to work around this issue today, though the solutions are not ergonomic. There are two paths:
We're not quite sure how we can improve the request ergonomics for mapping response data to each route. The router can only parse request data into a route, and then some other process in the server is responsible for a lot of business logic that results in some response data, and this happens fully outside our library. If you have any ideas, though, please do share! Compiler errors are also definitely out of our hands, unfortunately. Other languages allow some customization here, but sadly Swift does not. There may be some tricks we can employ, though, to improve things, if anyone has ideas! We already avoid some overloads in some places and instead prefer introducing new types because the errors are better. For your particular runtime error, can you post a full example? The code your provide is not quite enough for me to figure out the problem. |
Beta Was this translation helpful? Give feedback.
-
Hi, Request Ergonomic
This idea is very basic but should only work in Swift 5.7 😂. Having all public protocol Routable {
var response: any Codable { get }
} implementation example for var response: any Codable {
switch self {
case .fetch: return AppFetchResponse.self
case .builds(let buildsRoute): return buildsRoute.response
case .branches(let branchesRoute): return branchesRoute.response
case .buildWorkflows(let buildWorkflowsRoute): return buildWorkflowsRoute.response
}
} Light modification on @available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
public func request<Value: Decodable>(
_ route: Route,
decoder: JSONDecoder = .init()
) async throws -> (value: route.response, response: URLResponse) {
let (data, response) = try await self.request(route)
do {
return (try decoder.decode(route.response, from: data), response)
} catch {
throw URLRoutingDecodingError(bytes: data, response: response, underlyingError: error)
}
} This is just a raw idea I have to play with it and see how it perform and if it feasible. |
Beta Was this translation helpful? Give feedback.
-
Hi,
This library has a lot of great ideas and features to improve it I will focus only on the issues that I face using it.
I have implemented 10 endpoints of this API only GET to try it(I will implement more in the coming days). The 3 main issues I face are regarding request ergonomics, errors and DSL limitations(in no particular order). Most of the issues are related to the limitations of Swift itself but I feel that I have to talk about them since I face them.
DSL Limitations
Let's consider this API
/apps/:app-slug/builds
it has one required parameter theapp-slug
and 12 possible query parameters.When I implemented it I have to limit myself to 6 for it to work. I did try various approaches without success so I did disable the last 6 of them. I know the issue is related to variadic generic not supported in the languages for the moment and I know it is coming soon too.
Can adding this
swiftSettings: [ .unsafeFlags(["-enable-experimental-variadic-generics"]) ]
be considered in Package.swift or is it too early ?Request Ergonomic
When doing a request we have to give the type of the output. This is not ideal, the person that uses the client is not always the person that wrote it and sometimes the user doesn't know which response to use. To go around this I did put the response type to use in the documentation of endpoint(
.fetch
here) something more typesafe would be great.Errors
ResultBuilder errors can be too cryptic this is not an issue with the library but I have to talk about it since it comes up a lot(just a few examples below).
This will raise this issue.
Type of expression is ambiguous without more context
The real issue is due to the missing
Path
aroundParse
.This will raise
Cannot infer contextual base in reference to member 'memberwise'
andInitializer 'init(_:with:)' requires the types '(AppsRoute.FetchSearchOptions.SortByFetchSearchOptions, String, Int)' and '()' be equivalent
But the issue here is that in
FetchSearchOptions.init
the parameter are not in the same order as in theQuery
above.When doing working on some test I stumble on this error
caught error: "L’opération n’a pas pu s’achever. (Parsing.PrintingError erreur 1.)"
.This happens when the route has optional
SearchOption
and I don't know how to fix it.Beta Was this translation helpful? Give feedback.
All reactions