Simple RESTful API in rust created with actix-web. (Routing, models, JWT auth).

Overview

rust-simple-api

Simple RESTful API created with rust, actix-web, Diesel, JWT.

Running application

Manual

  • Firstly generate a secret.key which will be used for JWT enocding/decoding. head -c16 /dev/urandom > src/secret.key
  • Run cp .env.example .env to create environmental variables file, edit variables to match your needs.
  • Create PostgreSQL database in pgAdmin, postgres cli or using diesel cli (if diesel cargo package installed run diesel setup).
  • You can start use PostgreSQL via provided docker-compose.yml running docker-compose up or use a system service
  • Build release: cargo build --release
  • Run release version (on linux): target/release/api
  • Run debug version locally: cargo run

Run with docker

  • Firstly generate a secret.key which will be used for JWT enocding/decoding. head -c16 /dev/urandom > src/secret.key
  • Build docker image locally docker build -t users-api .
  • Edit environmental files in docker-compose.yml if needed.
  • Run docker-compose up to start the application. However, right now DB must be created before API service starts. Create database in pgAdmin, postgres cli or using diesel cli diesel setup. To run this command DATABASE_URL must be stored in .env. Run cp .env.example .env to use the default parameters before running diesel setup.

Routes

Route METHOD BODY Response Description
/api/users GET - [{"id": "..", "email": "..", "name": "..", "created_at": ".."}, { ... } Lists all users. Protected route, needs authorized user
/api/users/<user_id> GET - { "id": "f9f95d00-c9b4-4244-9048-f420ea38f873", "email": "..", "name": "..", "created_at": ".."} Finds user by id. Protected route, needs authorized user
/api/users POST {"email": "[email protected]", "name": "Some User", "password": "Pa$$w0rd"} Success - returs entity, failure - error message. Creates new user (signup route).
/api/login POST {"email": "[email protected]", "password": "Pa$$w0rd"} { "token": "ey...", "token_type": "bearer" } Returns token which should be added to Authorization header in order to reach secured routes
/api/refresh-token POST - Success returns new token: { "token": "ey...", "token_type": "bearer" }. Failure - 401 To refresh token a valid token is needed in Authorization header

Testing

  • Create db with diesel_cli: diesel setup --database-url='postgres://postgres:admin@localhost/test_api_db'. Here I am using test DB url which is also in .env file.
  • Run cargo test

ToDo's

  • Add Unit/Integration tests. (Increase coverage)
  • Pagination
You might also like...
Multi-platform desktop app to download and run Large Language Models(LLM) locally in your computer.
Multi-platform desktop app to download and run Large Language Models(LLM) locally in your computer.

Multi-platform desktop app to download and run Large Language Models(LLM) locally in your computer 🔗 Download | Give it a Star ⭐ | Share it on Twitte

List public items (public API) of Rust library crates. Enables diffing public API between releases.

cargo wrapper for this library You probably want the cargo wrapper to this library. See https://github.com/Enselic/cargo-public-items. public_items Li

Uma lib para a API do Brasil API (para o Rust)
Uma lib para a API do Brasil API (para o Rust)

Uma lib para a API do BrasilAPI (para o Rust) Features CEP (Zip code) DDD Bank CNPJ IBGE Feriados Nacionais Tabela FIPE ISBN Registros de domínios br

Simple Rust 🦀 api with Rocket 🚀

Car API Written in Rust & Rocket.rs 🦀 🚀 Running project Running by cargo You just need to run the following command: cargo run Running on docker Fi

My journey of learning rust as a web developer.

My journey of learning rust Low-level languages seem very interesting to me. I always wanted to learn a low-level language but never had the chance. T

Roadmap to becoming a Rust Web Developer in 2021

Roadmap to becoming a Rust Web Developer in 2021

A traditional web forum built in Rust with modern technology to be fast, secure, scalable, and stable.

Volksforo A traditional web forum built in Rust with modern technology to be fast, secure, scalable, and stable. Stack Rust actix-web askama ScyllaDB

Experimental web UI library for Rust.

tachys This is an extremely experimental web UI library for Rust, exploring concepts of compile-time, trait-based, low-allocation patterns for UI temp

This experiment shows connecting wasm-bindgen generated code to a good-web-game application.

GWG + wasm-bindgen example This experiment shows connecting wasm-bindgen generated code to a good-web-game application. It uses simple_logger crate to

Owner
null
A simple programming language, created for AP Computer Science

A simple programming language, created for AP Computer Science

Michelle S. 3 Sep 2, 2022
Simple rust interface to get derived analytical information of algorithmic market making models (M3).

af-rs Interact with the Portfolio protocol using Rust models to abstract the underlying pools. What we want: Given a uniswap pool with two tokens and

Primitive 5 Jul 11, 2023
Sorting-in-rust-jadyn-nicholas created by GitHub Classroom

Sorting in Rust Overview Traits Running the code and the tests To Do Overview This lab uses various sorting algorithms as examples several features of

null 0 Mar 24, 2022
disemvowel-in-rust-bante created by GitHub Classroom

Rust Disemvowel This is a simple lab where we'll use Rust to implement the disemvowel function that we covered in a previous C lab. What is Rust? Rust

null 0 Dec 7, 2021
learn_rust_rustlings-qinyuhang created by GitHub Classroom

rustlings ?? ❤️ Greetings and welcome to rustlings. This project contains small exercises to get you used to reading and writing Rust code. This inclu

The Learning&Training Hub of OS Kernel 2 Oct 22, 2022
kickable - a crate created to answer the age old question

kickable kickable is a crate created to answer the age old question... "Can I Kick It?" This package is for showcase purposes only. What is a kickable

@defstream 4 Jan 12, 2023
An LR(1) parser generator and visualizer created for educational purposes.

.lr An LR(1) parser generator and visualizer created for educational purposes. Table of Contents What is an LR(1) parser? Why did you make this? How c

Umut 80 Oct 21, 2024
Book - Actix user guides

User guides Actix User Guide Actix API Documentation (Development) Actix API Documentation (Releases) Actix Web User Guide Actix Web API Documentation

Actix 185 Dec 25, 2022
CloudLLM is a Rust library designed to seamlessly bridge applications with remote Language Learning Models (LLMs) across various platforms.

CloudLLM CloudLLM is a Rust library designed to seamlessly bridge applications with remote Language Learning Models (LLMs) across various platforms. W

null 4 Oct 13, 2023
A tray application for Windows that gives you push notifications and instant downloads of new posts, messages and stories posted by models you subscribe to on Onlyfans.

OF-notifier A tray application for Windows that gives you push notifications and instant downloads of new posts, messages and stories posted by models

Gentlemen Mercenary 10 Dec 20, 2022