N
Neon•16mo ago
adverse-sapphire

Connection via HTTP from a Rust-based environment

Hi there, Is there any way to contact neon via HTTP in a Rust-based serverless environment? We'd like to call Neon from Fastly by using an HTTP connection, is that possible?
4 Replies
rare-sapphire
rare-sapphire•16mo ago
Hey đź‘‹ Yep, I think that this should be doable, similar to how the serverless driver is implemented in JS:
https://github.com/neondatabase/serverless/
The serverless driver is just a small wrapper around the HTTP API. As mentioned here:
https://discord.com/channels/1176467419317940276/1193786856215687238/1194210831739650048
The basic idea is that you https POST some JSON to the /sql endpoint of your DB host, with a Neon-Connection-String header:
curl -v 'https://ep-adjective-noun-nnnn.aws-region-n.aws.neon.tech/sql' \
-H 'Neon-Connection-String: postgres://user:password@ep-adjective-noun-nnnn.aws-region-n.aws.neon.tech/main' \
-H 'Content-Type: application/json' \
--data '{
"query": "SELECT $1 AS greeting",
"params": [ "hello world" ]
}'
curl -v 'https://ep-adjective-noun-nnnn.aws-region-n.aws.neon.tech/sql' \
-H 'Neon-Connection-String: postgres://user:password@ep-adjective-noun-nnnn.aws-region-n.aws.neon.tech/main' \
-H 'Content-Type: application/json' \
--data '{
"query": "SELECT $1 AS greeting",
"params": [ "hello world" ]
}'
The thread above has some more nice information around this as well!
GitHub
GitHub - neondatabase/serverless: Connect to Neon PostgreSQL from s...
Connect to Neon PostgreSQL from serverless/worker/edge functions - neondatabase/serverless
adverse-sapphire
adverse-sapphireOP•16mo ago
Thanks, @Bobby Iliev Is this API stable enough? We would end up building our product on top of it and we want to make sure that is good enough and that it provides a good latency. Are there plans yet for it? Will it be under active development? Thanks
rare-sapphire
rare-sapphire•16mo ago
Let me pull in @andyhats who might have some more information on this!
flat-fuchsia
flat-fuchsia•16mo ago
Officially, no. But we've been pushing towards stabilising it. Breaking it at this point would break too many users so I wouldn't expect anything to break, although we do only regularly test it specifically from the js implementation. A few people have asked for a rust implementation so I am interested in writing one, although I've often seen it requested in wasm contexts so that's going to be interesting to design around

Did you find this page helpful?