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

Extended routes that return json doesn't compile #238

Open
jjude opened this issue Feb 6, 2020 · 3 comments
Open

Extended routes that return json doesn't compile #238

jjude opened this issue Feb 6, 2020 · 3 comments

Comments

@jjude
Copy link

jjude commented Feb 6, 2020

OS: Mac

Nimble:

# Dependencies
requires "nim >= 1.0.4", "jester"

If I have all code in a single file:

import jester, json

routes:
  get "/":
    var jsonResp = $(%*{"id": 2})
    resp Http200, jsonResp

It compiles and gets the expected output.

Now if I split this into two files:

main.nim

import jester
import api

routes:
  extend apiv1, "/api/v1"

and api.nim ( in the same folder)

import jester, json

router apiv1:
  get "/":
    var jsonResp = %*{"id": 2}
    echo jsonResp
    resp Http200, "hello"

Then it doesn't compile. The errors are:

jester.nim(1277, 9) Hint: Asynchronous route: apiv1. [User]
jester.nim(797, 9) Hint: 'settings' is declared but not used [XDeclaredButNotUsed]
jester.nim(1307, 26) Hint: 'apiv1ErrorHandler' is declared but not used [XDeclaredButNotUsed]
jester.nim(1280, 7) Hint: 'apiv1' is declared but not used [XDeclaredButNotUsed]
jester.nim(1277, 9) Hint: Asynchronous route: match. [User]
jester.nim(1283, 35) template/generic instantiation of `async` from here
/server/src/api.nim(5, 20) Error: undeclared identifier: '%*'
@rafatrace
Copy link

Did you try to access localhost:5000/api/v1 ? In my case it worked with the extra / at the end only. So if you do localhost:5000/api/v1/ you might get that response

@dom96
Copy link
Owner

dom96 commented Aug 27, 2020

Not really sure we can do much here in jester, it's more of a Nim limitation. You can export json in api.nim to work around it.

@hlizard
Copy link

hlizard commented Jan 11, 2022

What is more frustrating is that the error reported under Nim1.6.2 may no longer be "error: unknown identifier:", but become a more puzzling "error: unhandled exception: index 12 not in 0.. 11 [indexdefect]". When I first encountered this problem, I even began to doubt the reliability of Nim language. Fortunately, I finally found that the problem lies in import through compiling Nim1.4.9 myself. Now I think the only feasible way is to use include instead of import for extended routes module.

In addition, the following questions may be relevant:
#178

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants