Skip to content
/ canduma Public
forked from canduma/canduma

A Rust web server boilerplate with GraphQL API, Diesel, PostgreSQL and JWT authentication.

Notifications You must be signed in to change notification settings

PoeBlu/canduma

 
 

Repository files navigation

MIT license Status Status

Canduma rust server boilerplate

A Rust web server with GraphQL API, Diesel, PostgreSQL and JWT authentication.

This repository contains boilerplate rust code for getting a GraphQL prototype with JWT up and running quickly.

It uses actix-web, Juniper, Diesel and jsonwebtoken

Your own pull requests are welcome!

Benchmarks with insert into PostgreSQL

▶ ./bombardier -c 125 -n 10000000 http://localhost:3000/graphql -k -f body --method=POST -H "Content-Type: application/json" -s    
Bombarding http://localhost:3000/graphql with 10000000 request(s) using 125 connection(s)

10000000 / 10000000 [===========================================================================] 100.00% 28777/s 5m47s
Done!
Statistics        Avg      Stdev        Max
  Reqs/sec     28788.66    2183.47   34605.95
  Latency        4.32ms   543.07us   110.95ms
  HTTP codes:
    1xx - 0, 2xx - 10000000, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:    20.75MB/s

Collection of major crates used in Canduma

Required

  • Rustup
  • Nightly Toolchain: rustup default nightly
  • Diesel cli with postgres cargo install diesel_cli --no-default-features --features "postgres"
  • PostgreSQL database server or use our docker-compose.yml (require docker)

Getting Started

git clone https://github.com/clifinger/canduma.git
cd canduma
docker-compose up
cp .env.example .env
diesel setup --database-url='postgres://postgres:canduma@localhost/canduma'
diesel migration run
cargo run

Test the GraphQL API with Insomnia

Register

Register with Insomnia

Login

Login with Insomnia

Set Bearer JWT Token

Set JWT Token with Insomnia

Test authentication with JWT by getting all users

Set Token with Insomnia

Raw code for Insomnia

############ GraphQL Queries ############
mutation MemberRegister($registerInput: RegisterInput!) {
  register(input: $registerInput) {
    name
    email
    uuid
  }
}
mutation MemberLogin($loginInput: LoginInput!) {
  login(input: $loginInput) {
    bearer
    user {
      name
      uuid
      createdAt
      email
    }
  }
}
query MembersQuery {
  users {
    createdAt
    name
    email
    uuid
  }
}

############ Query Variables ############
{
	"registerInput": {
		"email": "me@me.me",
		"name": "John Doe",
		"password": "canduma"
	},
	"loginInput": {
		"email": "me@me.me",
		"password": "canduma"
	}
}

Build release

cargo build --release
cd target/release
./canduma

About

A Rust web server boilerplate with GraphQL API, Diesel, PostgreSQL and JWT authentication.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 89.8%
  • PLpgSQL 7.9%
  • TSQL 2.3%