Fetch the repository succeeded.
This action will force synchronization from pauljohn21/actix-web-rest-api-with-jwt, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
A simple CRUD backend app using Actix-web, Diesel and JWT
Or using Docker
secret.key.sample
to secret.key
or create your own key by running head -c16 /dev/urandom > secret.key
in command line (Linux/UNIX only) and copy to /src
folder.env.sample
to .env
and update the database connection string in DATABASE_URL
key.cargo build --release
target/release/actix-web-rest-api-with-jwt.exe
target/release/actix-web-rest-api-with-jwt
docker-compose -f docker-compose.local.yml up
for local environment or docker-compose -f docker-compose.prod.yml up
for production environmentlocalhost:8000
GET /api/ping
: Pingcurl -X GET -i 'http://127.0.0.1:8000/api/ping'
pong!
POST /api/auth/signup
: Signupcurl -X POST -i 'http://127.0.0.1:8000/api/auth/signup' \
-H "Content-Type: application/json" \
--data '{
"username": "user",
"email": "user@email.com",
"password": "4S3cr3tPa55w0rd"
}'
{
"username": string,
"email": string,
"password": string // a raw password
}
{
"message": "signup successfully",
"data": ""
}
{
"message": "User '{username}' is already registered",
"data": ""
}
POST /api/auth/login
: Logincurl -X POST -H 'Content-Type: application/json' -i 'http://127.0.0.1:8000/api/auth/login' \
--data '{"username_or_email":"user", "password":"4S3cr3tPa55w0rd"}'
{
"username_or_email": string,
"password": string // a raw password
}
{
"message": "login successfully",
"data": {
"token": string // bearer token
}
}
{
"message": "wrong username or password, please try again",
"data": ""
}
POST /api/auth/logout
: Logoutcurl -X POST -H 'Content-Type: application/json' \
-H 'Authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NzcyNTc4NzksImV4cCI6MTU3Nzg2MjY3OSwidXNlciI6ImMiLCJsb2dpbl9zZXNzaW9uIjoiYzUxNWE3NTg3NGYzNGVjNGFmNDJmNWE2M2QxMDVjMGYifQ.B9w6FxFdypb5GCRMKXZ9CZWFxQLFjvmPSusMCtcE-Ac' \
-i 'http://127.0.0.1:8000/api/auth/logout'
GET /api/address-book
: Get all people informationcurl -X GET -H 'Content-Type: application/json' \
-H 'Authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NzU4NzM4MjksImV4cCI6MTU3NjQ3ODYyOSwidXNlciI6ImMiLCJsb2dpbl9zZXNzaW9uIjoiZjU5N2M3MTIxZTExNDBhMGE0ZjE0YmQ4N2NjM2Q4MWUifQ.6qppDfRgOw45eExJ7MUEwpcu3AUXXe9_ifj_mp7k22k' \
-i 'http://127.0.0.1:8000/api/address-book'
{
"message": "ok",
"data": [
{
"id": int32,
"name": string,
"gender": boolean, // true for male, false for female
"age": int32,
"address": string,
"phone": string,
"email": string
}
]
}
GET /api/address-book/{id}
: Get person information by idcurl -X GET -H 'Content-Type: application/json' \
-H 'Authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NzU4NzM4MjksImV4cCI6MTU3NjQ3ODYyOSwidXNlciI6ImMiLCJsb2dpbl9zZXNzaW9uIjoiZjU5N2M3MTIxZTExNDBhMGE0ZjE0YmQ4N2NjM2Q4MWUifQ.6qppDfRgOw45eExJ7MUEwpcu3AUXXe9_ifj_mp7k22k' \
-i 'http://127.0.0.1:8000/api/address-book/2'
{
"message": "ok",
"data": {
"id": int32,
"name": string,
"gender": boolean, // true for male, false for female
"age": int32,
"address": string,
"phone": string,
"email": string
}
}
{
"message": "person with id {id} not found",
"data": ""
}
GET /api/address-book/{query}
: Search for person information by keywordcurl -X GET -H 'Content-Type: application/json' \
-H 'Authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NzU4NzM4MjksImV4cCI6MTU3NjQ3ODYyOSwidXNlciI6ImMiLCJsb2dpbl9zZXNzaW9uIjoiZjU5N2M3MTIxZTExNDBhMGE0ZjE0YmQ4N2NjM2Q4MWUifQ.6qppDfRgOw45eExJ7MUEwpcu3AUXXe9_ifj_mp7k22k' \
-i 'http://127.0.0.1:8000/api/address-book/user'
{
"message": "ok",
"data": [
{
"id": int32,
"name": string,
"gender": boolean, // true for male, false for female
"age": int32,
"address": string,
"phone": string,
"email": string
}
]
}
POST /api/address-book
: Add person informationcurl -X POST -H 'Content-Type: application/json' \
-H 'Authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NzU4NzM4MjksImV4cCI6MTU3NjQ3ODYyOSwidXNlciI6ImMiLCJsb2dpbl9zZXNzaW9uIjoiZjU5N2M3MTIxZTExNDBhMGE0ZjE0YmQ4N2NjM2Q4MWUifQ.6qppDfRgOw45eExJ7MUEwpcu3AUXXe9_ifj_mp7k22k' \
-i 'http://127.0.0.1:8000/api/address-book' \
--data '{
"name": "c",
"gender": true,
"age": 32,
"address": "addr",
"phone": "133",
"email": "e@q.com"
}
'
{
"name": string,
"gender": boolean, // true for male, false for female
"age": int32,
"address": string,
"phone": string,
"email": string
}
{
"message": "ok",
"data": ""
}
{
"message": "can not insert data",
"data": ""
}
PUT /api/address-book/{id}
: Update person information by idcurl -X PUT -H 'Content-Type: application/json' \
-H 'Authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NzU4NzM4MjksImV4cCI6MTU3NjQ3ODYyOSwidXNlciI6ImMiLCJsb2dpbl9zZXNzaW9uIjoiZjU5N2M3MTIxZTExNDBhMGE0ZjE0YmQ4N2NjM2Q4MWUifQ.6qppDfRgOw45eExJ7MUEwpcu3AUXXe9_ifj_mp7k22k' \
-i 'http://127.0.0.1:8000/api/address-book/2' \
--data '{
"name": "b",
"gender": true,
"age": 32,
"address": "addr",
"phone": "133",
"email": "b@q.com"
}
'
{
"name": string,
"gender": boolean, // true for male, false for female
"age": int32,
"address": string,
"phone": string,
"email": string
}
{
"message": "ok",
"data": ""
}
{
"message": "can not update data",
"data": ""
}
DELETE /api/address-book/{id}
: Delete person information by idcurl -X DELETE -H 'Content-Type: application/json' \
-H 'Authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NzU4NzM4MjksImV4cCI6MTU3NjQ3ODYyOSwidXNlciI6ImMiLCJsb2dpbl9zZXNzaW9uIjoiZjU5N2M3MTIxZTExNDBhMGE0ZjE0YmQ4N2NjM2Q4MWUifQ.6qppDfRgOw45eExJ7MUEwpcu3AUXXe9_ifj_mp7k22k' \
-i 'http://127.0.0.1:8000/api/address-book/2'
{
"message": "ok",
"data": ""
}
{
"message": "can not delete data",
"data": ""
}
curl -X OPTIONS -i 'http://127.0.0.1:8000/api/login' \
-H "Origin: http://example.com" -H "Access-Control-Request-Method: POST"
HTTP/1.1 200 OK
content-length: 0
access-control-max-age: 3600
access-control-allow-methods: POST,DELETE,GET,PUT
access-control-allow-origin: *
access-control-allow-headers: authorization,content-type,accept
date: Tue, 07 Jan 2020 15:17:48 GMT
{
"message": "invalid token, please login again",
"data": ""
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。