Let's create a CRUD Rest API in Rust using:
No specific framework
Serde to serialize and deserialize JSON
Postgres (database)
Docker
Docker Compo...
For further actions, you may consider blocking this person and/or reporting abuse
We are building an open source {free} Postman alternative: Hoppscotch - API request builder for web.
If you'd like to try an online API development / testing platform - we're building Hoppscotch.io.
hoppscotch / hoppscotch
👽 Open source API development ecosystem - https://hoppscotch.io
where cna I find more about Hoppscotch?
Documentation: docs.hoppscotch.io
GitHub: github.com/hoppscotch/hoppscotch
thank you. are you looking for collaborations?
I know the project
Great article, it's really good to see how simple it can be to work with Rust even for some applications that we would consider of higher level, like a REST API. I'd just like to point out that as I think this article may be suitable to beginners, you could've mentioned that you didn't follow best practices for REST APIs (like responses in plain text) for the sake of simplicity. Nonetheless, keep up the content!
hey Thiago, thanks for taking time to give feedback. yes the focus here is the connection between the rust app and the db, I didn't see many resources about this so I created one. in the future I might do something more focused on best practices, here I am focused on simplicity
are you currently building something with Rust?
I am building an open source authorization server. First I'm doing it with Typescript (Node) to understand what are the main problems building these. After that I'm going to rewrite it entirely in Rust.
I also have an article/video about typescript, if you are interested. IT's the same concept so you might find it useful.
Hi! I think the post is great! It's very interesting, and I may try to build it in a near future. However, I have a question. Could someone inject sql code with the request? Sorry for asking, I'm new in this world, and I love security
reply by ChatGPT4
This code does not appear to be vulnerable to SQL injection as it uses prepared statements, which are a security feature that helps prevent SQL injection attacks.
For example, in the handle_post_request function, the SQL query is prepared using placeholders and then executed with the user's inputs as parameters. The execute method of the Postgres client takes care of properly escaping the user inputs and preventing SQL injection attacks. Similarly, all other SQL queries in the code use prepared statements with placeholders.
Overall, it is good practice to use prepared statements or parameterized queries to prevent SQL injection attacks.
Thanks a lot. I really appreciate your explanation! I'm new, I started programming with the frontend pack we all know. Although, I find backend, database and talking to the os fascinating, specially Rust.
you are welcome! did you already coded something in Rust?
so we should be safe
from this article, i found rust very challenging just like approaching a girl
if she single, you're fuckdup
if she had bf, you also fuckdup
this comment is gold ahah! I think it's because I used no frameworks but I really like Rust
And I truly appreciate you for not using a framework. Not that I don’t appreciate frameworks, but most articles out there are always based on frameworks. But learning without frameworks (most times) provides comprehensive knowledge.
you are welcome
I came for threads like this. Learning Rust is a challenge for future me. But I can enjoy the memes and I’ll keep a pulse on the sentiment. I’m honestly extremely intimidated, sticking with GoLang for now.
For me it's just different but it has some great concepts I like. Why do you find it intimidating?
I’m getting most of my Rust info from @theprimeagen and I don’t know if I have the computing fundamentals down enough for it not to be a large undertaking. Lots of review of core concepts and such. Which is fine, just a bandwidth issue. I’ve been working on getting GoLang under my belt which I’m happy with. I’ve bookmarked your posts and when I’m ready to dive in I’ll circle back on your content.
nice, I know him. great livestreamer
Articles like this inspire me to look and dig deeper in Rust, thanks!
thank you so much! are you currently building somethign with Rust?
Nothing specific yet, just spending some time to learn it and discover language capabilities.
oh good luck then!
Great article,it's so helpful.
you are welome
check this part : All the code is available on GitHub (link in the video description)., we have added a Youtube video not Gihtub link . Else Thank you very good post .
yes, the link is generally available on the youtube description
It's the perfect post! Clean, precise, have some details... Very nice work. Thanks to sharing.
you are welcome Robson
why Error: error connecting to server: failed to lookup address information: nodename nor servname provided, or not known
it might be relative to the configuration in the docker compose file. did you try to clone the repo and do a docker compose build, then docker compose up?
Great tutorial, i dived in without knowledge of rust and i think i got most of it. It would be wonderful if you could make something like that about implementing authentication. Thank you
you are welcome! We'll see!
very usefull project
you are welcome Tomas. do you know Rust?
Great work!, am getting an error on build:
error[E0308]: mismatched types
--> src\main.rs:19:22
|
19 | const DB_URL: &str = std::env::var("DATABASE_URL");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected
&str
, foundResult<String, VarError>
|
= note: expected reference
&'static str
found enum
Result<std::string::String, VarError>
Any ideas?
try this line (with the exclamation mark)
const DB_URL: &str = env!("DATABASE_URL");
Hi, thank you for making this tutorial. however, there are a lot of things i don't understand. I'm following this steps but i get error a lot. For example, I do not get the trick behind settting the postgres db url . Can you kindly help out with that?
do i hve to spin up docker first?