You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
1.5 KiB

4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
  1. Testing out the Rust framework Actix-Web to create a JSON API CRUD Web App.
  2. ## API Demo
  3. ### Get Users
  4. ```
  5. curl -X GET http://localhost:7800/api/users/get/1
  6. ```
  7. ```
  8. {
  9. "name": "user1",
  10. "registration_date": "2020-05-09T06:17:26"
  11. }
  12. ```
  13. ```
  14. curl -X GET http://localhost:7800/api/users/get
  15. ```
  16. ```
  17. [
  18. {
  19. "name": "user1",
  20. "registration_date": "2020-05-09T06:17:26"
  21. },
  22. {
  23. "name": "user2",
  24. "registration_date": "2020-05-12T12:43:13"
  25. },
  26. {
  27. "name": "user3",
  28. "registration_date": "2020-05-15T07:47:50"
  29. }
  30. ]
  31. ```
  32. ### Create User
  33. ```
  34. curl -H "content-type: application/json" \
  35. -X POST \
  36. -i http://localhost:7800/do_registration \
  37. --data '{"name":"user4","password":"test"}'
  38. ```
  39. ```
  40. [
  41. {
  42. "name": "user1",
  43. "registration_date": "2020-05-09T06:17:26"
  44. },
  45. {
  46. "name": "user2",
  47. "registration_date": "2020-05-12T12:43:13"
  48. },
  49. {
  50. "name": "user3",
  51. "registration_date": "2020-05-15T07:47:50"
  52. },
  53. {
  54. "name": "user4",
  55. "registration_date": "2020-08-01T05:04:05"
  56. }
  57. ]
  58. ```
  59. ### DTO Validation
  60. ```
  61. curl -H "content-type: application/json" \
  62. -X POST \
  63. -i http://localhost:7800/do_registration \
  64. --data '{"name":"abc","password":"test"}' # min length for name is 4
  65. ```
  66. ```
  67. ValidationErrors({"name": Field([ValidationError { code: "length", message: None, params: {"value": String("abc"), "min": Number(4), "max": Number(10)} }])})
  68. ```
  69. ## Memory Usage
  70. 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.