Skip to content

Latest commit

 

History

History
68 lines (58 loc) · 1.21 KB

File metadata and controls

68 lines (58 loc) · 1.21 KB

rust-app

User CRUD API

Overview

This is a simple CRUD API for managing users using Actix Web and MongoDB.

Prerequisites

  • Rust installed
  • MongoDB running
  • Docker (optional, for containerization)

Running the API

Locally

Create a .env file with:

MONGO_URI=mongodb://localhost:27017
DATABASE_NAME=my_database

Then, run:

cargo run

Using Docker

Build and run the container:

docker build -t rust-app .
docker run -p 5050:3030 rust-app

API Endpoints

1. Get All Users

GET /users

curl --location 'http://localhost:5050/users'

2. Create a New User

POST /users

curl --location 'http://localhost:5050/users' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "John Doe",
    "email": "john@example.com",
    "age": 30
}'

3. Update a User

PUT /users/{user-id}

curl --location --request PUT 'http://localhost:5050/users/<user-id>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "John Doe",
    "email": "john.doe@example.com",
    "age": 37
}'

4. Delete a User

DELETE /users/{user-id}

curl --location --request DELETE 'http://localhost:5050/users/<user-id>'