Replies: 6 comments
-
Okay so after doing some digging I found out that the root cause of this failing is because of the following line in Route.swift in the swift-url-routing library. I forked both repositories and updated the method to this which solved the issue: @inlinable
public func parse(_ input: inout URLRequestData) throws -> Parsers.Output {
let output = try self.parsers.parse(&input)
if input.method != nil {
if input.method == "GET" {
try Method.get.parse(&input)
}
else if input.method == "POST" {
try Method.post.parse(&input)
}
}
try PathEnd().parse(input)
return output
} However I'm not sure how the underlying library works and if you want to just go ahead and hardcode the different HTTP methods in a beautiful nested if else statement 🤷♂️ |
Beta Was this translation helpful? Give feedback.
-
@anhar You can use the Method parser: Route(.case(HouseRoute.create)) {
Method.post
Path { "houses" }
}
The parser uses the The swift-url-routing Documentation is a good place to start to see what's available. It might be worth checking out the benchmark suite or even the PointFreeRouter for some example use cases. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
@anhar You're right. I meant the parser tries to parse the |
Beta Was this translation helpful? Give feedback.
-
Hi @anhar, Pat is correct in this situation, and your PR is not how the library should work. It may seem weird, but this logic in public func parse(_ input: inout URLRequestData) throws -> Parsers.Output {
let output = try self.parsers.parse(&input)
if input.method != nil {
try Method.get.parse(&input)
}
try PathEnd().parse(input)
return output
} In this method, So, in your first screenshot it is completely expected that With that said, I do believe you want to specify let houseRouter = OneOf {
Route(.case(HouseRoute.house)) {
Path { "houses"; UUID.parser() }
}
Route(.case(HouseRoute.create)) {
Method.post
Path { "houses"; }
}
} You can also specify |
Beta Was this translation helpful? Give feedback.
-
Also I am going to close this issue because it is not a bug in the library, and I am going to move it to a discussion so that we can continue discussing if you have more questions. |
Beta Was this translation helpful? Give feedback.
-
Hi y'all!
I saw the fantastic video on the PointFree website demonstrating the ability of this library and I wanted to play around with it.
I've got myself a simple little Vapor app with a
House
entity andRoom
entity in order to have a one-to-many relation.I'm setting up my router like this:
And then I have my handler function looks like this:
When running the request with a
POST
HTTP method it fails with the following error:However if I run the request with a
GET
HTTP method it succeeds even though aGET
request shouldn't have a HTTP body according to the spec:Now my question is how do I specify in the
setupRouter
method that the HouseRoute.create enum case maps to aPOST
HTTP method?Beta Was this translation helpful? Give feedback.
All reactions