Skip to content

fromscratchcode/rust-api-workshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Your First REST API in Rust

Getting started

  1. Install Rust using https://rustup.rs/.

  2. Clone this repo.

git clone https://github.com/fromscratchcode/rust-api-workshop.git
  1. The /starter directory contains the minimal version we’ll build from. The completed version lives in the /solution directory.

From /starter, run the code using cargo.

cd rust-api-workshop/starter
cargo run

If the code runs successfully, you should see:

Server listening on http://127.0.0.1:7878
  1. In a separate shell, verify the server is running:
curl http://localhost:7878/health

You should see:

{"status": "OK"}

REST API

We'll start from a minimal Axum server and progressively implement each of these routes.

  • GET /users
  • POST /users
  • GET /users/{id}
  • PUT /users/{id}
  • DELETE /users/{id}

Postman Collection (Optional)

There is a Postman collection in the /postman directory. You can import it into Postman to test the API endpoints contained in this repo.

Recreate this project from scratch (Optional)

cargo new rest-api
cd rest-api

cargo add axum
cargo add tokio --features full
cargo add serde --features derive
cargo add serde_json

License

The software is granted under the terms of the MIT License. For details see the file LICENSE included with the source distribution. All copyrights are owned by their respective authors.

About

Build your first REST API in Rust using Axum.

Resources

License

Stars

Watchers

Forks

Languages