question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for Path Parameters (Kotless DSL)

See original GitHub issue

Does the Kotless DSL currently support path parameters? I understand the documentation is a work in progress, so I tried using a few different common patterns e.g. /users/:id, /users/{id} just to check, and none of them seem to be routed to my endpoint.

If it’s the case that it’s not yet implemented, I’d be happy to give it a shot, especially if anyone could point me to the right place for it.

Thanks!

Update: After looking through the source code, it’s pretty obvious this just hasn’t been implemented yet. It seems like the two parts to implementing this are parsing and matching the route in the dispatcher, and then generating the right Terraform output, does that sound about right?

Also, would a PR be accepted if it only implemented this feature for the Kotless DSL?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:11
  • Comments:6

github_iconTop GitHub Comments

1reaction
hamadycissecommented, Feb 10, 2021

Will need it too please

1reaction
BlackHornetcommented, Dec 10, 2020

@Serdnad @Sitole

I found a solution that works for me.

Using Ktor I was able to use the Ktor “Locations”-Feature to set up the implementation for my route with path parameters.

Luckily Kotless does not create the terraform code for any “Locations” defined route. So I could write the aws terraform resources (as mentioned in my link above) in an extension file and add it to my terraform deployment.

In my extension I added the required:

  • aws_api_gateway_integration
  • aws_api_gateway_method (add the request_parameters)
  • aws_api_gateway_resource (using the path_part: e.g. {path})
  • aws_lambda_permission

in my case this looks like that

resource "aws_api_gateway_integration" "api_pathParam_get" {
  depends_on = [aws_api_gateway_resource.api_pathParam]
  rest_api_id = aws_api_gateway_rest_api.api.id
  resource_id = aws_api_gateway_resource.api_pathParam.id
  http_method = "GET"
  integration_http_method = "POST"
  type = "AWS_PROXY"
  uri = "arn:aws:apigateway:${data.aws_region.current.name}:lambda:path/2015-03-31/functions/${aws_lambda_function.merged_0.arn}/invocations"
}

resource "aws_api_gateway_method" "api_pathParam_get" {
  depends_on = [aws_api_gateway_resource.api_pathParam]
  rest_api_id = aws_api_gateway_rest_api.api.id
  resource_id = aws_api_gateway_resource.api_pathParam.id
  http_method = "GET"
  authorization = "NONE"

  request_parameters = {
    "method.request.path.pathParam" = true
  }
}

resource "aws_api_gateway_resource" "api_pathParam" {
  depends_on = [aws_api_gateway_resource.api]
  rest_api_id = aws_api_gateway_rest_api.api.id
  parent_id = aws_api_gateway_resource.api.id
  path_part = "{pathParam}"
}

resource "aws_lambda_permission" "api_pathParam_get" {
  statement_id = "api-pathparam-get"
  action = "lambda:InvokeFunction"
  function_name = aws_lambda_function.merged_0.arn
  principal = "apigateway.amazonaws.com"
  source_arn = "arn:aws:execute-api:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${aws_api_gateway_rest_api.api.id}/*/GET/api/*"
}

notice the path placeholder in the aws_lambda_permission.source_arn

As long as Kotless does not support Ktor Locations…i’m happy

Read more comments on GitHub >

github_iconTop Results From Across the Web

Question about routing path parameters Suppose I have a rout | Ktor ...
Question about routing path parameters Suppose I have a route get foo param1 bar When I access call parameters param1 the type is...
Read more >
Getting Started - Kotless Serverless Framework
Getting started. In this short tutorial we will overview all steps of Kotless-based application creation. Preliminaries. To use Kotless in you project you ......
Read more >
How to handle parameters in the URL using PATH in Karate ...
It's not a traditional URL (starting with http). But yes, I will try combos as you suggested. Thank you so much for your...
Read more >
a Serverless Framework for Kotlin - Kotless - arXiv
DSL that unites the cloud service provider's SDK and the deployment DSL. Using Kotless ... parameters that define the storage that Kotless might...
Read more >
wasabi Alternatives - Kotlin Web | LibHunt
A Spark DSL in idiomatic kotlin // dependency: com.sparkjava:spark-kotlin:1.0.0-alpha ... 8.4 1.8 wasabi VS kotless ... Wasabi supports route parameters.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found