We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
capture[String]('id)
/resource/{id}
capture[Int]
Typed Schema version: v0.12.0
v0.12.0
Consider having two API endpoints:
GET /resource/{id}
GET /resource/
Currently, the api endpoints definition using typed-schema would be:
def listBooks = prefix('books) :> PathEnd :> get :> key('listBooks) :> $$[List[String]] def getBook = prefix('books) :> capture[String]('bookId) :> PathEnd :> get :> key('getBook) :> $$[String]
and a handler for that could look like this:
class TestController[F[_]: Sync: RoutedPlus] { self => private val books = Map( "1" -> "Book1", "2" -> "Book2", "3" -> "Book3", "4" -> "Book4", ) def routes: H[Response] = MkService[H](api)(self) def listBooks(): List[String] = books.values.toList def getBook(bookId: String): String = books.getOrElse(bookId, "Not found") }
where PathEnd checks that all symbols in the request path have been consumed.
PathEnd
Final definition:
def api = getBook <|> listBooks
Actual:
> curl http://localhost:8080/books < "Not found"
Expected:
> curl http://localhost:8080/books < ["Book1","Book2","Book3","Book4"]
def api = listBooks <|> getBook
Actual matches expected
Let's modify getBook to accept Int:
getBook
Int
def getBook = prefix('books) :> capture[Int]('bookId) :> PathEnd :> get :> key('getBook) :> $$[String]
And call the API again (actual matches expected):
The text was updated successfully, but these errors were encountered:
Fix tofu-tf#364 and tofu-tf#389
c4af745
Merge pull request #442 from ulanzetz/fix-364-389
969d88e
Fix #364 and #389
Fixed in #442
Sorry, something went wrong.
No branches or pull requests
Problem
capture[String]('id)
matches empty string in paths like/resource/{id}
, butcapture[Int]
does notHow to reproduce
Consider having two API endpoints:
GET /resource/{id}
GET /resource/
Currently, the api endpoints definition using typed-schema would be:
and a handler for that could look like this:
where
PathEnd
checks that all symbols in the request path have been consumed.Case 1: Definition order
1.1
Final definition:
Actual:
Expected:
1.2
Final definition:
Actual matches expected
Case 2: Matching inconsistency
Final definition:
Let's modify
getBook
to acceptInt
:And call the API again (actual matches expected):
The text was updated successfully, but these errors were encountered: