falila / sqlx_demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rust SQLx REST API Demo

This Rust project serves as a demonstration of utilizing the SQLx crate to implement a RESTful API with CRUD operations for managing User data.

Prerequisites

Before running the project, ensure you have the following installed:

  • Rust: Install Rust
  • SQLite: For simplicity, this demo uses SQLite as the database. You can install it via your package manager or download it from SQLite website.

Setup

  1. Clone this repository:

    git clone git@github.com:falila/sqlx_demo.git
  2. Navigate to the project directory:

    cd sqlx_demo
  3. Build and run the project:

    cargo run

API Endpoints

The API provides the following endpoints for managing User data:

  • Create User:

    POST /users

  • Get All Users:

    GET /users

  • Get User by ID:

    GET /users/{id}

  • Update User by ID:

    PUT /users/{id}

  • Delete User by ID:

    DELETE /users/{id}

Example Usage

  • Create User:

    curl -X POST -H "Content-Type: application/json" -d '{"name":"John Doe","email":"john@example.com"}' http://localhost:8080/users
  • Get All Users:

    curl http://localhost:8080/users
  • Get User by ID:

    curl http://localhost:8080/users/1
  • Update User by ID:

    curl -X PUT -H "Content-Type: application/json" -d '{"name":"Updated Name","email":"updated@example.com"}' http://localhost:8080/users/1
  • Delete User by ID:

    curl -X DELETE http://localhost:8080/users/1

About


Languages

Language:Rust 95.6%Language:Shell 4.4%