Skip to content

Practice using Rust as a backend web server with Rocket

Notifications You must be signed in to change notification settings

JosueMolinaMorales/Rust-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust-API

Modules

Auth Module

POST /auth/login

Route to log a user in, returns the bearer token and user object

Authorization

No Auth Required

Request Body

{
    email: String,
    password: String
}

Response Body

{
    token: String,
    user: {
        name: String,
        email: String,
        username: String
    }
}

Potentional Errors

Error Code Error Reason
400 Email or Password is incorrect

POST /auth/register

Route to register a user, returns a bearer token and user object

Authorization

No Auth Required

Request Body

{
    name: String,
    username: String
    email: String,
    password: String
}

Response Body

{
    token: String,
    user: {
        name: String,
        email: String,
        username: String
    }
}

Potentional Errors

Error Code Error Reason
400 Email Exists, Username Exists

Record Module

GET /record/:user_id/all

Get all the records for a user

Authorization

A valid bearer token is required

Request Body

None

Response Body

{
    [
        {
            record_type: Secret || Password,
            _id: String,
            user_id: String,
            key: Option<String>,
            secret: Option<String>,
            service: Option<String>,
            password: Option<String>,
            email: Option<String>,
            username: Option<String>,
        }
    ]
}

Potentional Errors

Error Code Error Reason
400 User id is not a valid object id
401 User id and Id in token do not match

GET /record/:id

Get a specific record, :id is id of record

Authorization

A valid bearer token is required

Request Body

None

Response Body

{
    records: {
        record_type: Secret || Password,
        _id: String,
        user_id: String,
        key: Option<String>,
        secret: Option<String>,
        service: Option<String>,
        password: Option<String>,
        email: Option<String>,
        username: Option<String>,
    }
}

Potentional Errors

Error Code Error Reason
400 User id is not a valid object id
401 User id and Id in token do not match
404 Record was not found

POST /record

Create a new record

Authorization

A valid bearer token is required

Request Body

{
    record_type: "Secret" || "Password",
    key: Option<String>,
    secret: Option<String>,
    service: Option<String>,
    password: Option<String>,
    email: Option<String>,
    username: Option<String>,
}

Notes

  • A 400 will be thrown if record_type is Secret and key or secret is not in body
  • A 400 will be thrown if record_type is Secret and any password fields are passed in
  • A 400 will be thrown if record_type is Password and service, password, email or username are not in body
    • Email or Username can be passed in. Both do not need to be passed in
  • A 400 will be thrown if record_type is Password and any secret fields are passed in

Response Body

{
    id: String
}

Potentional Errors

Error Code Error Reason
400 User id is not a valid object id
401 User id and Id in token do not match

PATCH /record/:id

Update a record, :id is id of record

Authorization

A valid bearer token is required

Request Body

{
    service: Option<String>,
    password: Option<String>,
    email: Option<String>,
    username: Option<String>,
    key: Option<String>,
    secret: Option<String>,
}

Notes

  • A 400 will be thrown if record_type is Secret and any password fields are passed in
  • A 400 will be thrown if record_type is Password and any secret fields are passed in

Response Body

No body but response Code: 204

Potentional Errors

Error Code Error Reason
400 User id is not a valid object id
401 User id and Id in token do not match
404 Record was not found

DELETE /record/:id

Delete a record, :id is id of record

Authorization

A valid bearer token is required

Request Body

None

Response Body

No Body but reponse code is 204

Potentional Errors

Error Code Error Reason
400 User id is not a valid object id
401 User id and Id in token do not match
404 Record was not found

Search Module

GET /search/record/:user_id?page=&limit=&query=

Search a users record

Parameters

Parameter Name Description
Page The page of the search, used for pagination
Limit The amount of records to show
Query A text query to search for records

Authorization

A valid bearer token is required

Request Body

None

Response Body

{
    records: {
        record_type: Secret || Password,
        _id: String,
        user_id: String,
        key: Option<String>,
        secret: Option<String>,
        service: Option<String>,
        password: Option<String>,
        email: Option<String>,
        username: Option<String>,
    }
}

Potentional Errors

Error Code Error Reason
400 User id is not a valid object id
401 User id and Id in token do not match

User Module

GET /user/:user_id

Get the user object

Authorization

A valid bearer token is required

Request Body

None

Response Body

{
    id: String,
    email: String,
    username: String,
    name: String
}

Potentional Errors

Error Code Error Reason
400 User id is not a valid object id
401 User id and Id in token do not match
404 User does not exist

PATCH /user/:user_id

Update either the users email or password

Authorization

A valid bearer token is required

Request Body

{
    new_password: Option<String>,
    email: Option<String>,
    password: String
}

Response Body

None, return code is 204

Potentional Errors

Error Code Error Reason
400 User id is not a valid object id, Password does not match, new_password or email not sent
401 User id and Id in token do not match
404 User does not exist

About

Practice using Rust as a backend web server with Rocket

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published