Code Monkey home page Code Monkey logo

rust_rocket_api_authentication's Introduction

Rust rocket.rs - API with Authentication

An example of API written in Rust with the rocket.rs framework, with a JWT Authentication

Requirements

  1. Configure Rust to satisfy rocket.rs dependencies

Installation

  1. First run the migration
    diesel migration run
  2. Compile the code setting the DATABASE_URL environment variable
        export DATABASE_URL=mysql://username:password@localhost/heroes && cargo run

API

/auth/login

Get a jwt token for the user marcocastignoli

curl -X POST \
  http://localhost:8000/auth/login \
  -H 'content-type: application/json' \
  -d '{
	"username": "marcocastignoli",
	"password": "12345"
}'

/user

Call a protected route (use the token returned from the /auth/login API)

curl -X GET \
  http://localhost:8000/user \
  -H 'authentication: eyJ0eXAiOiJKV1QiLCJraWQiOm51bGwsImFsZyI6IkhTMjU2In0.eyJpc3MiOm51bGwsInN1YiI6Im1hcmNvY2FzdGlnbm9saSIsImF1ZCI6bnVsbCwiZXhwIjpudWxsLCJuYmYiOm51bGwsImlhdCI6bnVsbCwianRpIjpudWxsfQ.fnp0D8Qh1bTFv1zKTVGAxwjtyTCOqKuarRzBQabjiCI'

Thanks

Special thanks to @sean3z for this repo https://github.com/sean3z/rocket-diesel-rest-api-example and this tutorial https://medium.com/sean3z/building-a-restful-crud-api-with-rust-1867308352d8

rust_rocket_api_authentication's People

Contributors

eld avatar marcocastignoli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rust_rocket_api_authentication's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.