Actix-Demo/README.md

89 lines
1.6 KiB
Markdown
Raw Normal View History

Testing out the Rust framework Actix-Web to create a JSON API CRUD Web App.
2020-08-01 13:48:49 +00:00
## API Demo
### Get Users
2021-05-06 05:05:07 +00:00
```
curl -X GET http://localhost:7800/api/users
2020-08-01 13:48:49 +00:00
```
2021-05-06 05:05:07 +00:00
```
2020-08-11 07:31:50 +00:00
{
"name": "user1",
"registration_date": "2020-05-09T06:17:26"
}
2020-08-01 13:48:49 +00:00
```
2021-05-06 05:05:07 +00:00
```
curl -X GET http://localhost:7800/api/users
2020-08-01 13:48:49 +00:00
```
2021-05-06 05:05:07 +00:00
```
2020-08-11 07:31:50 +00:00
[
{
"name": "user1",
"registration_date": "2020-05-09T06:17:26"
},
{
"name": "user2",
"registration_date": "2020-05-12T12:43:13"
},
{
"name": "user3",
"registration_date": "2020-05-15T07:47:50"
}
]
2020-08-01 13:48:49 +00:00
```
### Create User
2021-05-06 05:05:07 +00:00
```
2020-08-11 07:31:50 +00:00
curl -H "content-type: application/json" \
-X POST \
-i http://localhost:7800/do_registration \
--data '{"name":"user4","password":"test"}'
2020-08-01 13:48:49 +00:00
```
2021-05-06 05:05:07 +00:00
```
[
{
"name": "user1",
"registration_date": "2020-05-09T06:17:26"
},
{
"name": "user2",
"registration_date": "2020-05-12T12:43:13"
},
{
"name": "user3",
"registration_date": "2020-05-15T07:47:50"
},
{
"name": "user4",
"registration_date": "2020-08-01T05:04:05"
}
]
2020-08-01 13:48:49 +00:00
```
### DTO Validation
2021-05-06 05:05:07 +00:00
```
2020-08-11 07:31:50 +00:00
curl -H "content-type: application/json" \
-X POST \
-i http://localhost:7800/do_registration \
--data '{"name":"abc","password":"test"}' # min length for name is 4
2020-08-01 13:48:49 +00:00
```
2021-05-06 05:05:07 +00:00
```
2020-08-01 13:48:49 +00:00
ValidationErrors({"name": Field([ValidationError { code: "length", message: None, params: {"value": String("abc"), "min": Number(4), "max": Number(10)} }])})
```
## Memory Usage
2021-04-21 05:52:24 +00:00
Memory usage as compared to interpreted languages was my primary motivation for looking into rust as a backend language. As of writing, the demo app uses less than 50MB of memory.
2021-05-06 05:05:07 +00:00
## License
AGPLv3