{"id":17197757,"url":"https://github.com/bkonkle/rust-example-caster-api","last_synced_at":"2025-02-24T02:31:13.476Z","repository":{"id":40997281,"uuid":"422781427","full_name":"bkonkle/rust-example-caster-api","owner":"bkonkle","description":"DEPRECATED: A demo Rust API implementation using Tokio, Axum, async-graphql, and SeaORM","archived":true,"fork":false,"pushed_at":"2024-02-26T11:24:53.000Z","size":731,"stargazers_count":130,"open_issues_count":15,"forks_count":13,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-02-23T11:13:24.574Z","etag":null,"topics":["graphql","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bkonkle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-10-30T04:18:07.000Z","updated_at":"2024-11-04T09:44:33.000Z","dependencies_parsed_at":"2023-11-07T14:49:36.695Z","dependency_job_id":"29803da4-7078-44eb-a137-a1a4c3d888f2","html_url":"https://github.com/bkonkle/rust-example-caster-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bkonkle%2Frust-example-caster-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bkonkle%2Frust-example-caster-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bkonkle%2Frust-example-caster-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bkonkle%2Frust-example-caster-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bkonkle","download_url":"https://codeload.github.com/bkonkle/rust-example-caster-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240405984,"owners_count":19796280,"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","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":["graphql","rust"],"created_at":"2024-10-15T01:57:15.952Z","updated_at":"2025-02-24T02:31:12.830Z","avatar_url":"https://github.com/bkonkle.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# Rust Async-GraphQL Example: Caster API\n\n[\u003cimg alt=\"Rust\" src=\"https://img.shields.io/badge/rust-2021-a72145?logo=rust\u0026style=flat\" /\u003e](https://www.rust-lang.org)\n[\u003cimg alt=\"GraphQL\" src=\"https://img.shields.io/badge/graphql-e10098?logo=graphql\u0026style=flat\" /\u003e](https://graphql.org)\n[\u003cimg alt=\"Tokio\" src=\"https://img.shields.io/badge/tokio-463103?logo=rust\u0026style=flat\" /\u003e](https://tokio.rs)\n[\u003cimg alt=\"Axum\" src=\"https://img.shields.io/badge/axum-7b5312?logo=rust\u0026style=flat\" /\u003e](https://crates.io/crates/axum)\n[\u003cimg alt=\"SeaORM\" src=\"https://img.shields.io/badge/SeaORM-032846?logo=postgresql\u0026style=flat\" /\u003e](https://github.com/SeaQL/sea-orm)\n\n**DEPRECATION WARNING:** This example is a few years old at this point, and will not be actively kept up-to-date. You may want to take a look at my new API framework, [Nakago](https://nakago.dev), which took the approach here and expanded on it with an async-first dependency injection system to make testing a lot easier. There's a version of this project there [in the `examples/async-graphql` folder](https://github.com/bkonkle/nakago/tree/main/examples/async-graphql).\n\nThis is an example app for the upcoming Rust video series by [Brandon Konkle](https://github.com/bkonkle). It implements a basic API to support a number of hypothetical frontends for the imaginary \"Caster\" app, a tool to help podcasters, broadcasters, and streamers coordinate show content with their co-hosts and guests. Limited to just the API to support the front end.\n\n## Local Development\n\nInstall Rust with [rustup](https://rustup.rs/).\n\n### Clippy\n\nFor helpful linting rools, install [Clippy](https://github.com/rust-lang/rust-clippy) with `rustup`:\n\n```sh\nrustup component add clippy\n```\n\nRun it with `cargo`:\n\n```sh\ncargo clippy --fix\n```\n\nConfigure the `rust-analyzer` VS Code plugin to use it (in _settings.json_):\n\n```json\n{\n    \"rust-analyzer.checkOnSave.command\": \"clippy\"\n}\n```\n\n### libclang\n\nThe `cargo-spellcheck` utility depends on [`libclang`](https://clang.llvm.org/doxygen/group__CINDEX.html).\n\nIn Ubuntu, the package to install is `libclang-dev`:\n\n```sh\nsudo apt install libclang-dev\n```\n\n### Cargo Make\n\nTo build scripts from the _Makefile.toml_, install Cargo Make:\n\n```sh\ncargo install cargo-make\n```\n\nRun \"setup\" to install some tooling dependencies:\n\n```sh\ncargo make setup\n```\n\n### Configuration\n\nConfiguration is unfortunately stored in two places, with the primary location being the [config](config/) folder. This folder contains hierarchical config files that are read by [Figment](https://github.com/SergioBenitez/Figment).\n\nTo set up your local environment, create a `local.toml` file and a `test.toml` file, using [`local.toml.example`](config/local.toml.example) and [`test.toml.example`](config/test.toml.example) as a guide.\n\nThe `local.toml` config is loaded by default in every run mode. In addition, an attempt to load a config file with the name of the run mode is also made - for example, `test.toml` when the `run_mode` is \"test\".\n\nThis config is read in as part of a [`lazy_static`](https://docs.rs/lazy_static/latest/lazy_static/) instance that is first initialized when the [`main.rs`](apps/api/src/main.rs) module from the `caster_api` app calls `caster_utils::config::get_config()`.\n\n### Environment Variables\n\nFor CLI tools, we have to provide a small [direnv](https://direnv.net/) `.envrc` file with a subset of our config values so that tools like `docker-compose` and `sqlx-cli` can read them. Use the `.envrc.example` as a guide.\n\n### Running Docker\n\nTo run the docker-compose formation with just the supporting services needed to run `cargo make dev`:\n\n```sh\ncargo make docker up -d\n```\n\nTo shut it down:\n\n```sh\ncargo make docker down\n```\n\nTo run docker-compose with the API app included:\n\n```sh\ncargo make docker-api up -d\n```\n\nTo shut it down:\n\n```sh\ncargo make docker-api down\n```\n\n### SQLx CLI\n\nInstall the SQLx CLI for running migrations:\n\n```sh\ncargo install sqlx-cli --no-default-features --features rustls,postgres\n```\n\nCreate a database based on the `DATABASE_URL` in the `.envrc`, if you haven't already:\n\n```sh\ncargo make db-create\n```\n\nRun migrations:\n\n```sh\ncargo make db-migrate\n```\n\nIf you want to wipe your database and start over:\n\n```sh\ncargo make db-reset\n```\n\n### Running the Local dev server\n\nUse `cargo` to run the dev server locally:\n\n```sh\ncargo make dev\n```\n\n### Update Dependencies\n\nFirst, install the `outdated` command for `cargo`:\n\n```sh\ncargo install --locked cargo-outdated\n```\n\nThen, update and check for any major dependency changes:\n\n```sh\ncargo update\ncargo outdated\n```\n\n### Running Integration Tests\n\nTo integration test, you need to have the Docker Compose stack with Postgres and Redis running locally, or within your CI pipeline.\n\nNOTE: This is destructive, and will wipe out data within your local database. See below for how to use an alternate test database locally.\n\nTo run the integration tests:\n\n```sh\ncargo make integration\n```\n\n#### Using an Alternate Test Database\n\nRunning integration tests is destructive. If you want to preserve your local data, use an alternate database for local integration testing. Create a `config/test.toml` file and customize the `DATABASE_URL`:\n\n```toml\n[database]\nname = \"caster_rust_test\"\nurl = \"postgresql://caster:caster@localhost:1701/caster_rust_test\"\n```\n\nSince the `RUN_MODE` environment variable is set by the `tasks.integration` make task to \"test\", this file will automatically be picked up by the config reader.\n\nNOTE: To manage this test database with the SQLx CLI, you'll need to temporarily edit your `.envrc` file to match the values above, and then run the command to reset the test database:\n\n```sh\ncargo make db-reset\n```\n\nYou can restore the original values in your `.envrc` afterwards.\n\n## Deployment\n\n### Building Docker Containers Locally\n\nTo build locally, use Buildkit:\n\n```sh\nDOCKER_BUILDKIT=1 docker build -t caster-api -f apps/api/Dockerfile .\n```\n\nTo clear the build cache:\n\n```sh\ndocker builder prune --filter type=exec.cachemount\n```\n\nTo inspect the local filesystem:\n\n```sh\ndocker run --rm -it --entrypoint=/bin/bash caster-api\n```\n\nTo inspect the full build context:\n\n```sh\ndocker image build --no-cache -t build-context -f - . \u003c\u003cEOF\nFROM busybox\nWORKDIR /build-context\nCOPY . .\nCMD find .\nEOF\n\ndocker container run --rm build-context\n```\n\nAnd to clean up the build context test image:\n\n```sh\ndocker image rm build-context\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbkonkle%2Frust-example-caster-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbkonkle%2Frust-example-caster-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbkonkle%2Frust-example-caster-api/lists"}