Skip to content
New issue

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

Route Decorator 🔌 #176

Closed
Ethosa opened this issue Nov 14, 2023 · 2 comments
Closed

Route Decorator 🔌 #176

Ethosa opened this issue Nov 14, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@Ethosa
Copy link
Contributor

Ethosa commented Nov 14, 2023

This feature provides compile-time route custom editing.

Simple example

serve "127.0.0.1", 5000:
  @AuthBasic
  post "/settings":
    echo username
    echo password
    ...

Also users will can write own decorators:

proc decoImpl(httpMethods: seq[string], routePath: string, statementList: NimNode) =
  statementList.insert(
    0,
    newCall("echo", newLit(routePath))
  )

# Register decorator in global scope at compile time
static:
  regDecorator("MyDecorator", decoImpl)
@Ethosa Ethosa added the enhancement New feature or request label Nov 14, 2023
@Ethosa Ethosa self-assigned this Nov 14, 2023
@Ethosa
Copy link
Contributor Author

Ethosa commented Nov 14, 2023

This also can used in SPA projects:

appRoutes "app":
  @GetUserAgent
  "/":
    tDiv:
      {userAgent}

Ethosa added a commit that referenced this issue Nov 14, 2023
@Ethosa
Copy link
Contributor Author

Ethosa commented Nov 14, 2023

Little hint: decorators can be combined:

serve ...:
  @AuthBasic
  @MyDeco
  @DeleteUnnecessary
  @Code404
  get "/":
    var x = 0
    return "Hello, world!"

@Ethosa Ethosa closed this as completed Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant