haxetink / tink_web

Tinkerbell Web Framework
https://haxetink.github.io/tink_web
43 stars 14 forks source link

Routing: Need fine grain capture #26

Open kevinresol opened 7 years ago

kevinresol commented 7 years ago

I am trying to generate a remote client for the Google Sheet API. Most things are done: e.g. read the doc and generate the classes, etc.

But I hit a point that I think I can't easily resolve. Here is a sample of the API: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.sheets/copyTo

The URL is as below: /spreadsheets/{spreadsheetId}/sheets/{sheetId}:copyTo

I tried to convert that to a tink_web metadata like so:

@:post('/spreadsheets/$spreadsheetId/sheets/$sheetId:copyTo')
public function copyTo(spreadSheetId:String, sheetId:String);

But tink_web complains there are surplus in the route (sheetId:copyTo) and a uncaptured argument (sheetId). Because the whole sheetId:copyTo string is treated as a whole. But obviously an identifier cannot contain symbols like that.

Is it possible that tink_web do a "partial" capture in that case? It would also be nice to support braces like ${sheetId}copyTo just in case someone wants combine a variable into a string.

back2dos commented 7 years ago

I'll have to think about this. For the proxy it's actually not a big deal, but for the router it's a bit of a nightmare.

Right now I would recommend something like this as a workaround:

@:post('/spreadsheets/$spreadsheetId/sheets/$copySheet')
public function copyTo(spreadSheetId:String, cmd:CopySheet);

abstract CopySheet to Partial {
  @:from static function ofSheedId(id:String):CopySheet;
}
kevinresol commented 7 years ago

Okay, that should work. But I still have the "tink_json cannot parse Dynamic" thingy :joy: