{"id":29647415,"url":"https://github.com/rhwd/rust-api-template","last_synced_at":"2025-07-22T03:37:18.246Z","repository":{"id":227931165,"uuid":"767860830","full_name":"rhwddy/rust-api-template","owner":"rhwddy","description":"Basic Rust JSON API template, cookie-based authentication included, made with axum and SQLx.","archived":false,"fork":false,"pushed_at":"2024-07-12T00:44:05.000Z","size":96,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-23T03:28:43.290Z","etag":null,"topics":["axum","cookiesession","rust","session-cookie","sqlx","tokio-rs","uuid"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rhwddy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-06T02:53:34.000Z","updated_at":"2025-01-14T17:14:55.000Z","dependencies_parsed_at":"2024-12-15T18:51:07.476Z","dependency_job_id":null,"html_url":"https://github.com/rhwddy/rust-api-template","commit_stats":null,"previous_names":["rhwd/rust-api-template","rhwddy/rust-api-template"],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/rhwddy/rust-api-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhwddy%2Frust-api-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhwddy%2Frust-api-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhwddy%2Frust-api-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhwddy%2Frust-api-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rhwddy","download_url":"https://codeload.github.com/rhwddy/rust-api-template/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhwddy%2Frust-api-template/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266420974,"owners_count":23926025,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["axum","cookiesession","rust","session-cookie","sqlx","tokio-rs","uuid"],"created_at":"2025-07-22T03:37:17.605Z","updated_at":"2025-07-22T03:37:18.226Z","avatar_url":"https://github.com/rhwddy.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rust JSON API template\n## Main Crates:\n - ### [SQLx](https://docs.rs/sqlx)\nSQLx is an async, pure Rust SQL crate featuring compile-time checked queries without a DSL.\n- ### [axum](https://docs.rs/axum)\naxum is a web application framework that focuses on ergonomics and modularity.\n\n## Additional crates\n[tokio](https://docs.rs/tokio) - [serde](https://docs.rs/serde) - [dotenv](https://docs.rs/dotenv) - [bcrypt](https://docs.rs/bcrypt) - [uuid](https://docs.rs/uuid)\n\n## Environment\n- ### Setup ENV variables by creating a `.env` at the root of the project:\n```\nPOSTGRES_HOST=\u003cYOUR PG HOST\u003e\nPOSTGRES_PORT=\u003cYOUR PG PORT\u003e\nPOSTGRES_USER=\u003cYOUR PG USER\u003e\nPOSTGRES_PASSWORD=\u003cYOUR PG PASSWORD\u003e\nPOSTGRES_DB=\u003cYOUR PG DATABASE NAME\u003e\n\nDATABASE_URL=\u003cYOUR PG DATABASE URL\u003e\n\nPGADMIN_DEFAULT_EMAIL=\u003cYOUR PG EMAIL\u003e\nPGADMIN_DEFAULT_PASSWORD=\u003cYOUR PG PASSWORD\u003e\n\nSIGNED_JAR_KEY=\u003cSIGNED JAR KEY\u003e\n```\n- ### Install SQLx CLI\nRun `cargo install sqlx-cli` to install it.\n\n## Database\n- ### Creating database\nRun `sqlx database create` to create a new database using the params given on `.env`.\n\n- ### Adding migrations\nUse `sqlx migrate add \u003cname\u003e` to add a new `.down.sql` and `.down.sql` migration files.\n\n- ### Running migrations\nTo run a your migrations use the command `sqlx migrate run`.\n\n## Models\n- Models are located in the `src/models` folder.\n- Models have multiple structs that aid on defining the JSON body of a certain request or the return of a query.\n- Model structs that are supposed to be used in a JSON body derive: `#[derive(Debug, Deserialize, Serialize)]`\n- Model structs that are used on queries derive: `#[derive(Debug, Deserialize, Serialize, Clone)]`\n\n## Handlers\n- Handler are located in the `src/handlers` folder.\n- Handlers are supposed to just call queries.\n\n## Routes\n- Routes are located in the `src/routes` folder.\n- Routes should appoint directly to an handler method, for example: `route(\"/users\", post(user::create))`\n\n## Config\n- Config are located in the `src/config` folder.\n- Contains the configuration for the App's Database, App state and Router\n\n## Utils\n- Utils are located in the `src/utils` folder.\n\n## Structs\n- Structs are located in the `src/structs` folder.\n- Unlike model structs, the structs located here are meant for the internal functions of the app. \n\n## Features\n- This template comes with an user [model](https://github.com/rhwd/rust-api-template?tab=readme-ov-file#models), [handler](https://github.com/rhwd/rust-api-template?tab=readme-ov-file#handlers) and [routes](https://github.com/rhwd/rust-api-template?tab=readme-ov-file#routes) setup.\n- User has a simple signed cookie based authentication setup.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhwd%2Frust-api-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frhwd%2Frust-api-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhwd%2Frust-api-template/lists"}