Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/emreyalvac/actix-web-jwt
Actix Web JWT
https://github.com/emreyalvac/actix-web-jwt
Last synced: 3 months ago
JSON representation
Actix Web JWT
- Host: GitHub
- URL: https://github.com/emreyalvac/actix-web-jwt
- Owner: emreyalvac
- Created: 2020-03-21T12:18:37.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-11T12:53:04.000Z (over 4 years ago)
- Last Synced: 2024-10-15T04:44:10.008Z (3 months ago)
- Language: Rust
- Size: 36.1 KB
- Stars: 154
- Watchers: 5
- Forks: 23
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Actix Web JWT Example
Simple backend app with Actix-web, JWT and MongoDB
(JWT Token, Protect Route, Login & Register)
*While developing the web service, I couldn't find good documentation or example (or up-to-date) to integrate jwt into my code. That's why I developed this example :)*
# Require
- [MongoDB](https://www.mongodb.com/)
# How to run
- Create database and collection in mongodb.
- Replace `DATABASE_NAME` and `USER_COLLECTION_NAME` with your database settings in `config.env` file.
- If you want to change `SECRET_KEY` for `JWT`, you can change in `config.env` file.# .env file
```
DATABASE_NAME=YOUR_DATABASE_NAME
USER_COLLECTION_NAME=YOUR_USERS_COLLECTION_NAME
SECRET_KEY=Xqv8jTGLxT
```# APIs
---# `POST /user/register`
```
curl -X POST -i 'http://127.0.0.1:8080/user/register' \
-H "Content-Type: application/json" \
--data '{
"name": "name",
"surname": "surname",
"email": "[email protected]",
"password": "password"
}'
```
### Response
```
{
"message": String,
"status": bool
}
```-------
# `POST /user/login`
```
curl -X POST -i 'http://127.0.0.1:8080/user/login' \
-H "Content-Type: application/json" \
--data '{
"email": "[email protected]",
"password": "password"
}'
```
### Response
```
{
"message": String,
"status": bool,
"token": String
}
```
---
# `POST /user/userInformations`
---
```
curl -X GET -H 'Content-Type: application/json' \
-H 'Authorization: Bearer TOKEN' \
-i 'http://127.0.0.1:8080/user/userInformations'
```
### Response
```
{
"user_id": String,
"name": String,
"surname": String,
"phone": String,
"email": String,
"password": String,
"birth_date": String
}
```
---
# `POST /user/protectedRoute`
```
curl -X GET -H 'Content-Type: application/json' \
-H 'Authorization: Bearer TOKEN' \
-i 'http://127.0.0.1:8080/user/protectedRoute'
```
### Response
```
bool
```