Skip to content

Latest commit

 

History

History
162 lines (127 loc) · 2.29 KB

README.md

File metadata and controls

162 lines (127 loc) · 2.29 KB

rust-api

A simple API made with Rust!

Table of content

Overview

Rust API is an API created for my studies on rust and REST APIs.

This api stores a user creation system, as well as a login system with authentication and validation of parameters, functions such as listing users, editing and deleting them.

Stack

Usage

After downloading the source code, run the following command to download the dependencies and build the project:

cargo build

Then set these environment variables in .env file:

HOST="127.0.0.1"
PORT=3000
DATABASE_URL=
JWT_SECRET=

Then run the following command to run the server:

cargo run

API

Create users

POST /users

Fields:

{
    "username": "[USERNAME]",
    "email": "[EMAIL]",
    "password": "[PASSWORD]"
}

Response:

{
    "id": "[ID]",
    "username": "[USERNAME]",
    "email": "[EMAIL]"
}

List users

GET /users

Response:

[
    {
        "id": "[ID]",
        "username": "[USERNAME]",
    },
    ...
]

List user info

GET /users/{ID}

Response:

{
    "id": "[ID]",
    "username": "[USERNAME]",
    "email": "[EMAIL]"
}

Login user

POST /login

Fields:

{
    "email": "[EMAIL]",
    "password": "[PASSWORD]"
}

Response:

{
    "token": "[TOKEN]"
}

Update user

PUT /users Requires authentication

Fields:

{
    "username": "[USERNAME]",
    "email": "[EMAIL]",
    "password": "[PASSWORD]"
}

Response:

{
    "message": "User updated successfully!"
}

Delete user

DELETE /users Requires authentication

Fields:

{
    "password": "[PASSWORD]"
}

Response:

{
    "message": "User deleted successfully!"
}