Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stpfeffer/rust-api
A simple API in Rust
https://github.com/stpfeffer/rust-api
Last synced: 8 days ago
JSON representation
A simple API in Rust
- Host: GitHub
- URL: https://github.com/stpfeffer/rust-api
- Owner: StPfeffer
- Created: 2024-04-29T01:15:20.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-05-15T15:38:53.000Z (6 months ago)
- Last Synced: 2024-05-16T04:41:08.570Z (6 months ago)
- Language: Rust
- Size: 49.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rust API
This is a simple API written in [Rust](https://www.rust-lang.org/).
## How to run
This code is using a [PostgreSQL](https://www.postgresql.org/) container in [Docker](https://www.docker.com/).
### Docker
To start the PostgreSQL container:
`docker-compose -f docker-compose.no_api.yml up -d`
To end the container:
`docker-compose -f docker-compose.no_api.yml down`
### Cargo
After the container is running, you can execute the application using the following command:
`cargo run`
## Migrations
Generate reversible migration scripts containing both "up" and "down" SQL files:
`sqlx migrate add -r "description"`
To syncronize the database schema with the migration scripts in "`./migrations`", execute:
`sqlx migrate run`
## Endpoints
### Authentication
#### /api/auth/register
Handles the user registration within the API by invoking the `register` route function.
#### /api/auth/login
Handles the user login by invoking the `login` route function.
#### /api/auth/logout
Handles the user logout by invoking the `logout` route function.
### User
#### /api/users/me
This endpoint is accessible exclusively to users with a valid JWT. This function extracts the user's information from the request, filters out sensitive files such as the password, and then returns the result.
#### /api/users
This endpoint is restricted to users having the "admin" role and a valid JWT.