Code Monkey home page Code Monkey logo

actix-web-jwt's Introduction

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

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

actix-web-jwt's People

Contributors

emreyalvac avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.