All Projects → SakaDream → Actix Web Rest Api With Jwt

SakaDream / Actix Web Rest Api With Jwt

Licence: mit
A simple CRUD backend app using Actix-web, Diesel and JWT

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Actix Web Rest Api With Jwt

Cerberus
A demonstration of a completely stateless and RESTful token-based authorization system using JSON Web Tokens (JWT) and Spring Security.
Stars: ✭ 482 (+138.61%)
Mutual labels:  restful-api, jwt
Sureness
A simple and efficient open-source security framework that focus on protection of restful api.
Stars: ✭ 254 (+25.74%)
Mutual labels:  restful-api, jwt
Codeigniter Jwt Sample
CodeIgniter JWT Sample
Stars: ✭ 144 (-28.71%)
Mutual labels:  restful-api, jwt
golang api
This is a source code of my golang restful api series on youtube.
Stars: ✭ 36 (-82.18%)
Mutual labels:  jwt, restful-api
Gin Boilerplate
The fastest way to deploy a restful api's with Gin Framework with a structured project that defaults to PostgreSQL database and JWT authentication middleware stored in Redis
Stars: ✭ 559 (+176.73%)
Mutual labels:  restful-api, jwt
X Restful Api Generator Koa
一个基于 Koa 的 RESTful API 服务脚手架。 A RESTful API generator for Koa
Stars: ✭ 18 (-91.09%)
Mutual labels:  restful-api, jwt
Node Express Mongoose Passport Jwt Rest Api Auth
Node, express, mongoose, passport and JWT REST API authentication example
Stars: ✭ 146 (-27.72%)
Mutual labels:  restful-api, jwt
Jwtpermission
基于token验证的Java Web权限控制框架,使用jjwt,支持redis和db多种存储方式,可用于前后端分离项目,功能完善、使用简单、易于扩展。
Stars: ✭ 186 (-7.92%)
Mutual labels:  jwt
Awesome Iam
👤 Identity and Access Management Knowledge for Cloud Platforms
Stars: ✭ 186 (-7.92%)
Mutual labels:  jwt
Django Restfulapi
基于 Django 3.x 的 RESTfulAPI 风格的项目模板,用于快速构建企业级高性能的服务端。
Stars: ✭ 184 (-8.91%)
Mutual labels:  restful-api
Supra Api Nodejs
❤️ Node.js REST API boilerplate
Stars: ✭ 182 (-9.9%)
Mutual labels:  jwt
Rest Crud
RESTFul CRUD Example with Node.js and Mysql
Stars: ✭ 188 (-6.93%)
Mutual labels:  restful-api
Yii2 Angular Boilerplate
Yii2 REST API + Angular10 Boilerplate (Frontend/Backend)
Stars: ✭ 194 (-3.96%)
Mutual labels:  jwt
Hospital
医院预约挂号微信小程序(Spring Boot、Vue、Uni-app)
Stars: ✭ 182 (-9.9%)
Mutual labels:  jwt
Route
Route - Fast, flexible routing for PHP, enabling you to quickly and easily build RESTful web applications.
Stars: ✭ 200 (-0.99%)
Mutual labels:  restful-api
Vsphere Automation Sdk Rest
REST (Postman and JavaScript) samples and API reference documentation for vSphere using the VMware REST API
Stars: ✭ 182 (-9.9%)
Mutual labels:  restful-api
Generator Loopback Vue
app版本管理,(热更新)前后端分离,vue page分页功能,authenticate 权限控制,accesstoken机制,credentials,CI,docker
Stars: ✭ 202 (+0%)
Mutual labels:  restful-api
Koa Vue Notes Web
🤓 This is a simple SPA built using Koa as the backend, Vue as the first frontend, and React as the second frontend. Features MySQL integration, user authentication, CRUD note actions, and Vuex store modules.
Stars: ✭ 200 (-0.99%)
Mutual labels:  jwt
Nextjs Jwt Authentication
A proof of concept app for demonstrating authentication of Next.js app with JWT.
Stars: ✭ 191 (-5.45%)
Mutual labels:  jwt
Spring Webflux Security Jwt
A JWT authorization and authentication implementation with Spring Reactive Webflux, Spring Boot 2 and Spring Security 5
Stars: ✭ 190 (-5.94%)
Mutual labels:  jwt

Actix-web REST API with JWT

CI Docker CICD

A simple CRUD backend app using Actix-web, Diesel and JWT

Require

Or using Docker

How to run

Manual

  • Rename 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
  • Create a database in postgres cli or pgAdmin tool
  • Rename .env.sample to .env and update the database connection string in DATABASE_URL key.
  • Build with release profile: cargo build --release
  • Run release binary in command line/terminal.
    • Windows: target/release/actix-web-rest-api-with-jwt.exe
    • Linux/UNIX: target/release/actix-web-rest-api-with-jwt
  • Enjoy! 😄

Docker

  • Enter into project directory
  • Run docker-compose -f docker-compose.local.yml up for local environment or docker-compose -f docker-compose.prod.yml up for production environment
  • Enjoy! 😄

Note for yew-address-book-client

APIs

Address: localhost:8000

GET /api/ping: Ping

curl -X GET -i 'http://127.0.0.1:8000/api/ping'
  • Response:
    • 200 OK
    pong!
    

POST /api/auth/signup: Signup

curl -X POST -i 'http://127.0.0.1:8000/api/auth/signup' \
  -H "Content-Type: application/json" \
  --data '{
    "username": "user",
    "email": "[email protected]",
    "password": "4S3cr3tPa55w0rd"
  }'
  • Request body:
{
   "username": string,
   "email": string,
   "password": string       // a raw password
}
  • Response
    • 200 OK
    {
       "message": "signup successfully",
       "data": ""
    }
    
    • 400 Bad Request
    {
       "message": "User '{username}' is already registered",
       "data": ""
    }
    

POST /api/auth/login: Login

curl -X POST -H 'Content-Type: application/json' -i 'http://127.0.0.1:8000/api/auth/login'  \
  --data '{"username_or_email":"user",  "password":"4S3cr3tPa55w0rd"}'
  • Request body:
{
   "username_or_email": string,
   "password": string       // a raw password
}
  • Response
    • 200 OK
    {
       "message": "login successfully",
       "data": {
         "token": string      // bearer token
       }
    }
    
    • 400 Bad Request
    {
       "message": "wrong username or password, please try again",
       "data": ""
    }
    

POST /api/auth/logout: Logout

curl -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 information

curl -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'
  • Header:
    • Authorization: bearer <token>
  • Response
    • 200 OK
    {
       "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 id

curl -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'
  • Param path:
    • id: int32
  • Header:
    • Authorization: bearer <token>
  • Response
    • 200 OK
    {
       "message": "ok",
       "data": {
         "id": int32,
         "name": string,
         "gender": boolean,      // true for male, false for female
         "age": int32,
         "address": string,
         "phone": string,
         "email": string
       }
    }
    
    • 404 Not Found
    {
       "message": "person with id {id} not found",
       "data": ""
    }
    

GET /api/address-book/{query}: Search for person information by keyword

curl -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'
  • Param path:
    • query: string
  • Header:
    • Authorization: bearer <token>
  • Response
    • 200 OK
    {
       "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 information

curl -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": "[email protected]"
  }
'
  • Header:
    • Authorization: bearer <token>
  • Request body:
    {
      "name": string,
      "gender": boolean,      // true for male, false for female
      "age": int32,
      "address": string,
      "phone": string,
      "email": string
    }
    
  • Response
    • 201 Created
    {
      "message": "ok",
      "data": ""
    }
    
    • 500 Internal Server Error
    {
      "message": "can not insert data",
      "data": ""
    }
    

PUT /api/address-book/{id}: Update person information by id

curl -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": "[email protected]"
  }
'
  • Param path:
    • id: int32
  • Header:
    • Authorization: bearer <token>
  • Request body:
{
  "name": string,
  "gender": boolean,      // true for male, false for female
  "age": int32,
  "address": string,
  "phone": string,
  "email": string
}
  • Response
    • 200 OK
    {
      "message": "ok",
      "data": ""
    }
    
    • 500 Internal Server Error
    {
      "message": "can not update data",
      "data": ""
    }
    

DELETE /api/address-book/{id}: Delete person information by id

curl -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'
  • Param path:
    • id: int32
  • Header:
    • Authorization: bearer <token>
  • Response
    • 200 OK
    {
      "message": "ok",
      "data": ""
    }
    
    • 500 Internal Server Error
    {
      "message": "can not delete data",
      "data": ""
    }
    

brower OPTIONS curl request example

curl -X OPTIONS -i 'http://127.0.0.1:8000/api/login' \
  -H "Origin: http://example.com" -H "Access-Control-Request-Method: POST"
  • Response
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

Errors:

  • Invalid or missing token
    • Status code: 401 Unauthorized
    • Response:
    {
      "message": "invalid token, please login again",
      "data": ""
    }
    
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].