Parsing a literal string from an enum using switf-parsing and url-routing

Viewed 27

I'm using this PointFree library Swift URL Routing to try and build a router in my app. However, the docs are fairly light and I can't work out how to get just a literal string out of a route to place into the path.

For instance...

enum MyRoute {
  case getItem(itemID: String)
}

Should have a path like /item/theItemID.

In the docs it shows how to do this with a number...

Route(.case(MyRoute.getItem(itemID:)) {
  Path {
    "item"
    Digits()
  }
}

But my value is not a number it's a string and I can't seem to work out how to do this. (Which seems like it should be a trivial thing ) If I use Digits() then it complains that it doesn't have an Int.

1 Answers

OK... a bit more searching in the discussions of the Swift URL Parsing repo and I found this...

Route(.case(MyRoute.getItem(itemID:)) {
  Path {
    "item"
   Parse(.string)
  }
}

So it was as trivial as I had expected it to be.

Related