All Projects → abankspdx → rust-api

abankspdx / rust-api

Licence: other
A sample REST API in Rust, using Docker, Iron, Diesel and Postgres

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to rust-api

Webapp.rs
A web application completely written in Rust. 🌍
Stars: ✭ 1,888 (+10388.89%)
Mutual labels:  diesel
Plume
Federated blogging application, thanks to ActivityPub (now on https://git.joinplu.me/ — this is just a mirror)
Stars: ✭ 1,615 (+8872.22%)
Mutual labels:  diesel
kibou
Kibou is a lightweight federated social networking server written in Rust. This is only a mirror! The real repository is on https://git.cybre.club/kibouproject/kibou
Stars: ✭ 41 (+127.78%)
Mutual labels:  diesel
editor.sh
Yet another live programming environment for collaborative code editing and running.
Stars: ✭ 29 (+61.11%)
Mutual labels:  diesel
FullstackRustDemo
Novelty website + bucket questions implementation.
Stars: ✭ 40 (+122.22%)
Mutual labels:  diesel
partner
partner
Stars: ✭ 16 (-11.11%)
Mutual labels:  diesel
Actix-Blog
A personal blog powered by rust-lang and actix-web
Stars: ✭ 42 (+133.33%)
Mutual labels:  diesel
rust cms
使用Rust编写一个CMS(内容管理系统)可以做为个人博客,公司网站
Stars: ✭ 32 (+77.78%)
Mutual labels:  diesel
Ironos
Open Source Soldering Iron firmware for Miniware and Pinecil
Stars: ✭ 3,945 (+21816.67%)
Mutual labels:  iron
runner
forum write in rust
Stars: ✭ 46 (+155.56%)
Mutual labels:  iron
team
Free Knowledge Groupware
Stars: ✭ 63 (+250%)
Mutual labels:  iron

Rust API Example

Written with Iron, Diesel, Docker

This is not meant to be "production" ready by any means. I just was having trouble finding a "full" example of an API in Rust, so I decided to make one to better understand. I've been working with Rust for only a few weeks, so this was mostly for me to learn. I thought others might find use for it too.

Structure

There are three "layers" to this API.

  • Handlers
  • Services
  • Types

This is generally how I construct APIs in other languages as well. Handlers coalesce HTTP requests into business logic units, which live in Services. Services interract with base datatypes (Types). Types also contain required traits for Diesel to run.

I've included a basic JWT implementation and the surrounding Iron code, with a couple examples of where/how you'd use it.

Tests

I wrote tests for JWT and Password hashing services, as those services aren't bound to an HTTP request/Database connection. You could probably make this a bit more "testable," whether by implementing DI or constructing struct-based service instances.

Libraries used

  • iron = "0.5.1"
  • router = "0.5.1"
  • time = "0.1.38"
  • serde = "1.0.11"
  • serde_derive = "1.0.11"
  • serde_json = "1.0.2"
  • diesel = { version = "0.16.0", features = ["postgres"] }
  • diesel_codegen = { version = "0.16.0", features = ["postgres"] }
  • dotenv = "0.9.0"
  • bcrypt = "0.1"
  • rand = "0.3"
  • bodyparser = "0.7.0"
  • frank_jwt = "2.5.1"

Code reviews are welcome!

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].