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

Error: undeclared identifier: 'decodeString' #30

Open
atcol opened this issue Jul 6, 2022 · 2 comments
Open

Error: undeclared identifier: 'decodeString' #30

atcol opened this issue Jul 6, 2022 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@atcol
Copy link

atcol commented Jul 6, 2022

I'm struggling to adapt your tests to a working basic example because I get this error:

presto-0.0.4/presto/route.nim:300:13 Error: undeclared identifier: 'decodeString'

Here's my example:

import presto

proc main() {.async.} =                                                        
   let serverAddress = initTAddress("127.0.0.1:30180")                          
   let router = RestRouter()                                                    
   router.api(MethodGet, "/exchange/{exchange}/orderbook/{symbol}/bid") do (    
     exchange: string, symbol: string                                           
   ) -> RestApiResponse:                                                        
     return RestApiResponse.error(Http505, "\"Some error\"", "application/json")
   var sres = RestServerRef.new(router, serverAddress)                          
   let server = sres.get()                                                      
   server.start()                                                               
                                                                                
 main()                                                                         

I am new to Nim and was hoping to get a basic REST API created with async background tasks providing data (hence the use of Async)

@alrevuelta
Copy link

Same issue here.

@alrevuelta
Copy link

My code in case it helps:

import
    std/[json,sequtils],
    presto/[route, server],
    chronos

let serverAddress = initTAddress("127.0.0.1:9000")
proc validate(pattern: string, value: string): int =
  if pattern.startsWith("{") and pattern.endsWith("}"): 0
  else: 1
var router = RestRouter.init(validate)

# GET /test
router.api(MethodGet, "/test/{a}") do (a: string) -> RestApiResponse:
    echo "Enter in get"
    let jsonString = """{"key": 3.14}"""
    return RestApiResponse.response(jsonString, contentType="application/json")

var sres = RestServerRef.new(router, serverAddress)
let restServer = sres.get()
restServer.start()

proc main() {.async.} = 
  while true:
    await sleepAsync(1000)

when isMainModule:
  waitFor main()

@cheatfate cheatfate added the documentation Improvements or additions to documentation label Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants