Hello all,
I am currently trying to send an HTTP request using std/httpclient but in my development environment I need to ignore ssl errors. I understand that in order to do this I need to pass in a custom SslContext to the HttpClient used to make the request. I've written the following procedure:
import std/httpclient
import std/json
import std/net
proc get_api_token*(endpoint: string, username: string, password: string): string =
let body = %*{
"username": username,
"password": password
}
var ctx: SslContext = newContext()
var client: HttpClient = newHttpClient()
let response: Response = client.request(endpoint, HttpMethod.HttpPost, $body)
return $response.code()
I have been stuck at creating the new SslContext where it fails to compile with the following message:
Error: undeclared identifier: 'newContext'
candidates (edit distance, scope distance); see '--spellSugg
est':
(3, 4): 'SslContext'
(3, 4): 'getContent'
I'm not sure why newContext is an undeclared identifier since I am importing the std/net library as per the docs. Any help is greatly appreciated.
You need to compile your program with -d:ssl in order to use SSL stuff. If you also want the errors to not show up in VSCode, create a file named config.nims and put this there:
switch("define", "ssl")
Figured it out not long after I posted. Thank you very much for your response.
What I ended up doing was making a nim.cfg file at the project root with -d:ssl in it. I think this achieves the same thing as what you proposed. Now I can compile and my LSP stopped throwing errors and the newContext proc is detected by the LSP.