v79 / APIViaduct

A serverless RESTful API and router written in Kotlin for AWS Lambda
0 stars 0 forks source link

Path parameters - extract path parameters such as /get/{id} #4

Closed v79 closed 3 months ago

v79 commented 3 months ago

Implementation is complete but it is "stringy" and there's no way to specify the type of a path parameter.

Hypothetically, one could extend the route definition to include type information, something like this?

/get/{id:Integer} or /put/{isbn:ISBN} (with a data class ISBN(val isbn: Integer)) but I don't think that would be stable enough and would require some reflection to find the implementating class. I'd almost certainly need an annotation on the ISBN class to flag it for matching).

v79 commented 3 months ago

Alternatively:

get("/{id}", ISBN::class, { _: Unit -> Response.OK()})

v79 commented 3 months ago

.net takes the {name:type} approach but it only works for a core set of types (int, bool, etc etc). They allow clever things like maxlength attributes too.