1

See code in gist: https://gist.github.com/C06A/e80b783a1d34cc9d80e339da0d7b5b53

This is a small sample project I try to make with Micronaut in Kotlin.

Unfortunately the only parameters binding I was able to do as in the code. They require the pattern in the template and typed as String. However I would like to be able to do something like in comments. So there won't be a pattern in the template and types as Number and List (or Array would work as well).

Is it possible to do that and why it doesn't work for me?

Jaydeep
  • 1,686
  • 1
  • 16
  • 29
C.A.B.
  • 465
  • 4
  • 12

2 Answers2

1

The first argument you can just simply type as a Number. The second argument however you would have to pull in as a String because its not possible for Micronaut to know how the part of the URI should be converted to a list.

/repeat/5/1,2,3,4 ? /repeat/6/1|2|3 ? /repeat/7/[1,2,3]

James Kleeh
  • 12,094
  • 5
  • 34
  • 61
  • Thanx. It makes sense. However I thought it would reverse the logic of template. URI template would convert collection into URL path, so it would make sense if by finding parameter of Collection type it would try to parse multiple elements into it. – C.A.B. May 24 '19 at 02:21
  • For example if template looks like "{/name*}" the collection will be converted into "/value1/value2/value3". Why not convert same back? – C.A.B. May 24 '19 at 02:31
  • @C.A.B. Because we can't make the assumption – James Kleeh May 24 '19 at 04:00
  • You changed (expanded) the UriTemplate syntax to include patterns matching. I believe RFC only calls for numeric field length after colon in the placeholder. – C.A.B. May 25 '19 at 01:05
  • What I suggesting is not an assumption, but logical IMHO usage. Matching may be a bit more complex, but logic is implemented during compilation. For example path "/repeat/5/1,2,3,4" would match pattern "/repeat/{value}{/stack}" while "/repeat/5/1/2/3/4" would match -- "/repeat/{value}{/stack*}". I don't know about "|"-separated list (don't see what it would relay to), but your last example should match my pattern without "*". – C.A.B. May 25 '19 at 01:10
  • Do you know the place I can submit more detailed suggestion for improvement? – C.A.B. May 25 '19 at 01:16
0

I found somewhere that the pattern "/{+stack}" would match the string including slashes. This is not what I am looking for, but helpful in the mean time. This also doesn't allow to make this parameter optional. Oh well! :-(

C.A.B.
  • 465
  • 4
  • 12
  • `{/+stack}` would make it optional – James Kleeh May 25 '19 at 18:07
  • I tried this even though it is very mach agains the URI Template RFC. However it doesn't work. I got the error: "The route declares a uri variable named [+stack], but no corresponding method argument is present". This makes sense according to URI Template concepts. – C.A.B. May 27 '19 at 21:41
  • It should be `{/stack+}` – James Kleeh May 28 '19 at 19:36
  • This is not at all like URI Templates. Is there document listing differences between Micronaut URI Templar’s and corresponding RFC? – C.A.B. May 30 '19 at 02:26
  • There was a year ago, but you didn't provide this king of doc. I think it would be really useful. – C.A.B. May 21 '20 at 02:25