Skip to content

Linzell/actix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

BackEnd Project - Use Actix and SurrealDB to build a RESTful API

Actix SurrealDB

Project Description

This project is a RESTful API built with Actix and SurrealDB. It is a simple API that allows users to create, read, update, and delete users and items.

Project Features

  • CRUD Users

  • CRUD Items

  • Add Guards to Routes

  • Add Logger

  • Add Error Handling

  • Update SurrealDB to 1.0.0-beta.9

  • Add Authentication

  • Add Authorization

  • Add Governor

  • Add Caching

  • Add Rate Limiting

  • Add Pagination

  • Add Sorting

  • Add Filtering

  • Add Search

  • Add WebSockets

  • Add GraphQL

  • Add OpenAPI

  • Add Tests

  • Add Documentation

Project Dependencies

[dependencies]
surrealdb = "1.0.0-beta.9"
actix-web = { version = "4.2.1", features = ["rustls"] }
serde = { version = "1.0.177", features = ["derive"]}
serde_json = "1.0.103"
dotenv = "0.15.0"
futures = "0.3"
thiserror = "1"
env_logger = "0.10.0"

Project Structure

The project is structured as follows:

.
├── Cargo.lock
├── Cargo.toml
├── README.md
├── src
│   ├── api
│   │   ├── item_api.rs
│   │   └── user_api.rs
│   ├── model
│   │   ├── item_model.rs
│   │   └── user_model.rs
│   ├── utils
│   │   ├── macros.rs
│   │   └── try_forms.rs
│   ├── error.rs
│   ├── main.rs
│   └── prelude.rs
└── tests
    ├── integration
    │   ├── item_api_test.rs
    │   └── user_api_test.rs
    └── unit
        ├── item_test.rs
        └── user_test.rs

Project Setup

Prerequisites

  • Rust

Installation

  1. Clone the repository
git clone
  1. Install dependencies
cargo build
  1. Run the project
cargo run

API Documentation

User API

Get all Users

curl --location --request GET 'http://localhost:8080/users'
response: 200 OK -- Users List

Get Users by IDs Array

curl --location --request GET 'http://localhost:8080/usersByIds'
--header 'Content-Type: application/json' \
--data-raw '{
    "ids": [
        "1",
        "2",
        "3"
    ]
}'
response: 200 OK -- Users List

Get Users by parameters

curl --location --request GET 'http://localhost:8080/usersBy'
--header 'Content-Type: application/json' \
--data-raw '{
    "param": [
      "name": "John Doe",
    ]
}'
response: 200 OK -- Users List

Create User

curl --location --request POST 'http://localhost:8080/users' \
--header 'Content-Type: application/json' \
--data-raw '{
    "cid": "1",
    "public_key": "0x1234567890",
    "private_key": "0x1234567890",
    "name": "John Doe",
    "version": 1,
    "avatar": "https://example.com/avatar.png",
    "email": "[email protected]",
    "creation_date": "2020-01-01T00:00:00Z",
    "online_state": "online",
    "follow_ids": [
        "2",
        "3"
    ],
    "is_visible": true,
    "is_inactive": false,
  }'
response: 200 OK -- User Created

Get User

curl --location --request GET 'http://localhost:8080/users/1'
response: 200 OK -- User

Update User

curl --location --request PUT 'http://localhost:8080/users/1' \
--header 'Content-Type: application/json' \
--data-raw '{
    "cid": "1",
    "public_key": "0x1234567890",
    "private_key": "0x1234567890",
    "name": "John Doe",
    "version": 1,
    "avatar": "https://example.com/avatar.png",
    "email": "[email protected]",
    "creation_date": "2020-01-01T00:00:00Z",
    "online_state": "online",
    "follow_ids": [
        "2",
        "3"
    ],
    "is_visible": true,
    "is_inactive": false,
  }'
response: 200 OK -- User Updated

Delete User

curl --location --request DELETE 'http://localhost:8080/users/1'
response: 200 OK -- User:id Deleted

Item API

Get all Items

curl --location --request GET 'http://localhost:8080/items'
response: 200 OK -- Items List

Get Items by IDs Array

curl --location --request GET 'http://localhost:8080/itemsByIds'
--header 'Content-Type: application/json' \
--data-raw '{
    "ids": [
        "1",
        "2",
        "3"
    ]
}'
response: 200 OK -- Items List

Get Items by parameters

curl --location --request GET 'http://localhost:8080/itemsBy'
--header 'Content-Type: application/json' \
--data-raw '{
    "param": [
      "name": "Item 1",
    ]
}'
response: 200 OK -- Items List

Create Item

curl --location --request POST 'http://localhost:8080/items' \
--header 'Content-Type: application/json' \
--data-raw '{
    "cid": "1",
    "name": "Item 1",
    "owner_id": "1",
    "version": 1,
    "content": [ "1", "2", "3" ],
    "creation_date": "2020-01-01T00:00:00Z",
    "edit_date": "2020-01-01T00:00:00Z",
    "tag_ids": [
        "2",
        "3"
    ],
    "follower_ids": [
        "2",
        "3"
    ],
    "is_visible": true,
    "is_archived": false,
  }'
response: 200 OK -- Item Created

Get Item

curl --location --request GET 'http://localhost:8080/items/1'
response: 200 OK -- Item

Update Item

curl --location --request PUT 'http://localhost:8080/items/1' \
--header 'Content-Type: application/json' \
--data-raw '{
    "cid": "1",
    "name": "Item 1",
    "owner_id": "1",
    "version": 1,
    "content": [ "1", "2", "3" ],
    "creation_date": "2020-01-01T00:00:00Z",
    "edit_date": "2020-01-01T00:00:00Z",
    "tag_ids": [
        "2",
        "3"
    ],
    "follower_ids": [
        "2",
        "3"
    ],
    "is_visible": true,
    "is_archived": false,
  }'
response: 200 OK -- Item Updated

Delete Item

curl --location --request DELETE 'http://localhost:8080/items/1'
response: 200 OK -- Item:id Deleted

Testing

[soon]

License

GNU General Public License v3.0

About

Back-end in Rust (Actix and SurrealDB)

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages