An open API service indexing awesome lists of open source software.

https://github.com/oguzhan18/rust_mongodb_auth

Simple Auth API written in Rust
https://github.com/oguzhan18/rust_mongodb_auth

authentication authentication-backend mongoatlas mongodb rust rust-auth rust-lang

Last synced: about 2 months ago
JSON representation

Simple Auth API written in Rust

Awesome Lists containing this project

README

        

# Rust MongoDB Auth API Documentation

This API provides endpoints for user registration and login using Actix web framework and MongoDB.

## Endpoints

### Register

Registers a new user with the provided username and password.

- **URL**: `/register`
- **Method**: `POST`
- **Request Body**: JSON

#### Request Body Parameters

| Parameter | Type | Description |
|-----------|--------|----------------------------|
| `username`| string | User's username |
| `password`| string | User's password |

#### Responses

- **200 OK**: User registered successfully
- **500 Internal Server Error**: Failed to register user

### Login

Authenticates a user with the provided username and password.

- **URL**: `/login`
- **Method**: `POST`
- **Request Body**: JSON

#### Request Body Parameters

| Parameter | Type | Description |
|-----------|--------|----------------------------|
| `username`| string | User's username |
| `password`| string | User's password |

#### Responses

- **200 OK**: Login successful
- **401 Unauthorized**: Invalid credentials
- **500 Internal Server Error**: Failed to login

## Rust Code Overview

The API is implemented in Rust programming language using Actix web framework and MongoDB driver. Below are the key components of the Rust code:

- **User Struct**: Represents a user with `username` and `password` fields.

- **register Function**: Handles user registration by inserting user data into the MongoDB collection. It takes user data and the MongoDB collection as arguments and returns a HTTP response indicating the registration status.

- **login Function**: Handles user login by verifying user credentials against the MongoDB collection. It takes user data and the MongoDB collection as arguments and returns a HTTP response indicating the login status.

- **main Function**: Initializes the Actix web server, connects to the MongoDB database, selects the 'users' collection, and binds the routes for registration and login.

## Usage

1. Make sure Rust and MongoDB are installed on your system.
2. Run `cargo run` to start the API server.
3. Send POST requests to `/register` and `/login` endpoints using JSON body to register and login users.

## MongoDB Configuration

Update the MongoDB connection URI in the main function with your MongoDB Atlas credentials and cluster information.

```rust
let client = Client::with_uri_str("mongodb+srv://:@/")
.await
.expect("Failed to initialize MongoDB client");
```

Replace ``, ``, and with your MongoDB Atlas credentials and cluster information.

## For Support
For support, send an email to [email protected] or you are invited to our telegram channel https://t.me/vsform_tr

## Contact Me


oguzhan1881
oguzhan18
oguzhancart
o%c4%9fuzhan-%c3%a7art-b73405199/
oguzhan18
oguzhan_cart
cart188
@oguzhancart
oguzhan18/