Search⌘ K
AI Features

Create Endpoint

Explore how to create a web endpoint in Rust that accepts JSON parameters and calls a database handler function. Understand module use, cloning versus referencing for parameter handling, and implement tests to ensure endpoint reliability.

We'll cover the following...

Creates the handler

In this lesson, we need an endpoint that receives the parameters through the webserver.

We need to make our create_product function public. To do so, we add the pub keyword at the beginning to change the corresponding line.

Rust 1.40.0
pub fn create_product(new_product: NewCompleteProduct, conn: &SqliteConnection) -> Result<i32> {

We also need to add derive ...