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.
-
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
[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"
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
- Rust
- Clone the repository
git clone
- Install dependencies
cargo build
- Run the project
cargo run
curl --location --request GET 'http://localhost:8080/users'
response: 200 OK -- Users List
curl --location --request GET 'http://localhost:8080/usersByIds'
--header 'Content-Type: application/json' \
--data-raw '{
"ids": [
"1",
"2",
"3"
]
}'
response: 200 OK -- Users List
curl --location --request GET 'http://localhost:8080/usersBy'
--header 'Content-Type: application/json' \
--data-raw '{
"param": [
"name": "John Doe",
]
}'
response: 200 OK -- Users List
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
curl --location --request GET 'http://localhost:8080/users/1'
response: 200 OK -- 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
curl --location --request DELETE 'http://localhost:8080/users/1'
response: 200 OK -- User:id Deleted
curl --location --request GET 'http://localhost:8080/items'
response: 200 OK -- Items List
curl --location --request GET 'http://localhost:8080/itemsByIds'
--header 'Content-Type: application/json' \
--data-raw '{
"ids": [
"1",
"2",
"3"
]
}'
response: 200 OK -- Items List
curl --location --request GET 'http://localhost:8080/itemsBy'
--header 'Content-Type: application/json' \
--data-raw '{
"param": [
"name": "Item 1",
]
}'
response: 200 OK -- Items List
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
curl --location --request GET 'http://localhost:8080/items/1'
response: 200 OK -- 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
curl --location --request DELETE 'http://localhost:8080/items/1'
response: 200 OK -- Item:id Deleted
[soon]