Mario Zupan
Apr 24, 2023 ⋅ 14 min read

Create an async CRUD web service in Rust with warp

Mario Zupan I'm a software developer originally from Graz but living in Vienna, Austria. I previously worked as a full-stack web developer before quitting my job to work as a freelancer and explore open source. Currently, I work at Netconomy.

Recent posts:

Using Aws Lambda And Aws Cloudfront To Optimize Image Handling

Using AWS Lambda and CloudFront to optimize image handling

Leverage services like AWS Lambda, CloudFront, and S3 to handle images more effectively, optimizing performance and providing a better UX.

Nitish Sharma
Apr 12, 2024 ⋅ 12 min read
Building Web-Based Terminal Components With Termino.js

Building web-based terminal components with Termino.js

Explore Termino.js, an open source library for integrating web-based terminals into applications, in this introduction article.

Chibuike Nwachukwu
Apr 11, 2024 ⋅ 6 min read
How To Build A Custom Gpt: Step By Step Tutorial

How to build a custom GPT: Step-by-step tutorial

Let’s see why and how to build custom GPTs — personalized versions of ChatGPT that act as custom chatbots to serve a specific purpose.

Peter Aideloje
Apr 10, 2024 ⋅ 7 min read
Jest Adoption Guide: Overview, Examples, And Alternatives

Jest adoption guide: Overview, examples, and alternatives

Jest is feature-rich testing framework that comes with several in-built features that make it powerful and easy to use.

Ibiyemi Adewakun
Apr 9, 2024 ⋅ 12 min read
View all posts

9 Replies to "Create an async CRUD web service in Rust with warp"

  1. I did not know about warp and I really liked. It seems more streamlined than Actix. I will give it a try. Thanks for sharing.

  2. Hello!
    Thanks for your article.
    To be able to use the API consumed by axios in a recent browser, I had to reconfigure the CORS as follows:

    // CORS
    let cors = warp::cors()
    .allow_methods(&[Method::GET, Method::POST, Method::DELETE])
    .allow_headers(vec![header::CONTENT_TYPE, header::AUTHORIZATION])

    The listing of allowed methods & headers is mandatory.
    Moreover, I had to put the line .with(cors) after the line .recover(handle_rejection), otherwise, you will have a CORS issue after a rejection is raised.

    Hope it helps 🙂

  3. Hey!

    Thanks for the feedback and for the heads up about the order of CORS, that definitely makes more sense that way. 🙂

  4. Hello Mario! Nice article, but I just performance tested this code (with my own DB) – it comes down to about 17k req/sec, but Rocket achieves 65k… of course I just stumbled upon warp, but there must be a limiting factor somewhere in the pg connector which I wasn’t able to pinpoint.

  5. Hey Bernd!

    That’s interesting for sure. There could be several reasons for this. It could be related to the connection pool, but also Warp-inherent. I’m not aware of any up2date benchmarks comparing the two frameworks.

    Also, since this post has been published over a year ago, it still uses Tokio pre 1.x, so using fully upgraded dependencies might improve this as well.

    Generally, keep in mind that this example was just a very basic tutorial on how to build a simple DB-backed web-app with Warp. It’s entirely unoptimized, since this simply wasn’t a relevant factor in the tutorial.

  6. Hello there Mario!

    Thanks a lot for this awesome guide, this was pretty much exactly what I was looking for 🙂
    Even someone like me, who is just dipping his toes into the rust waters, was able to get it up and running while (hopefully) understanding at least some parts of the whole thing 😀

    I had some issues though as it seems that since the tutorial was written rust/some dependencies changed a few things around. So I went ahead and updated all dependencies (while adding cargo-husky and itconfig as I simply love those two ^^).

    The result can be seen here: https://github.com/ItsNothingPersonal/warp-postgres-example

    If there is any problem with me hosting it there, just tell me and I’ll delete it 🙂

    Again, thanks for your work!

  7. Hey Sebastian!

    That’s great – I’m very happy the article was useful to you and big props on “making it your own”, which is the ultimate goal a tutorial such as this can have – to enable readers to extend and build something on top of it. Great work!

    The issues with dependencies are an annoying reality in any not-yet-fully-stable field such as Rust’s async-web, but I’m glad you were able to resolve them. 🙂

    Thanks for your feedback. 🙂

  8. Hi Mario, thanks for this tutorial. I’m in the process of learning rust and found this useful, picked up a few tips but must admit some of it I still don’t grasp.

    I managed to get it working and even satisfied cargo clippy by ensuring all linting rules were adhered to. There seems to be no reason for many of the closures and just supplying the actual function as the argument was sufficient e.g. .map_err(reject::custom)?; as suggested by clippy.

    I’ve had a little dabble with axum and it seems simpler than warp but it’s very early days for me, anyway I’ve got 2 more of your blogs to work through now, Build a Rust + WebAssembly frontend web app with Yew and Full-stack Rust: A complete tutorial with examples. I can’t wait to get stuck in, thanks again.

Leave a Reply