{"id":19793073,"url":"https://github.com/harrisonhemstreet/webservice_tutorial","last_synced_at":"2025-07-28T16:31:25.809Z","repository":{"id":204453329,"uuid":"711892609","full_name":"HarrisonHemstreet/webservice_tutorial","owner":"HarrisonHemstreet","description":"A tutorial for building webservices in Rust","archived":false,"fork":false,"pushed_at":"2023-11-27T03:36:04.000Z","size":74,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-21T15:02:26.859Z","etag":null,"topics":["actix-web","api","postgresql","rust","rust-lang","sqlx","tutorial","webservice"],"latest_commit_sha":null,"homepage":"https://docs.rs/crate/webservice_tutorial/latest","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/HarrisonHemstreet.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}},"created_at":"2023-10-30T11:41:17.000Z","updated_at":"2024-10-07T20:36:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"76ce61f7-16dc-4470-a024-78225f1c0877","html_url":"https://github.com/HarrisonHemstreet/webservice_tutorial","commit_stats":null,"previous_names":["harrisonhemstreet/webservice_tutorial"],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HarrisonHemstreet%2Fwebservice_tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HarrisonHemstreet%2Fwebservice_tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HarrisonHemstreet%2Fwebservice_tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HarrisonHemstreet%2Fwebservice_tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HarrisonHemstreet","download_url":"https://codeload.github.com/HarrisonHemstreet/webservice_tutorial/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227932101,"owners_count":17843003,"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":["actix-web","api","postgresql","rust","rust-lang","sqlx","tutorial","webservice"],"created_at":"2024-11-12T07:08:47.171Z","updated_at":"2024-12-03T13:54:39.540Z","avatar_url":"https://github.com/HarrisonHemstreet.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Web Service Tutorial in Rust\n\n## Overview\n\nThis project serves as a comprehensive tutorial for building a web service using the Rust programming language. It covers various aspects, from setting up a PostgreSQL database to handling JSON responses.\n\n## Technologies Used\n\n- **Rust**: The core programming language used for this project.\n- **Tokio**: An asynchronous runtime for Rust.\n- **SQLx**: A Rust library for connecting to PostgreSQL databases.\n- **Dotenv**: A Rust crate for handling `.env` files.\n- **Serde**: A Rust crate for serializing and deserializing data structures.\n- **Actix-Web**: A Rust framework for building web services.\n- **Chrono**: A time manipulation library for Rust.\n\n## Documentation\n\nTo generate documentation for this project:\n\n```bash\ncargo doc --open\n```\n\nAlternatively, you can find documentation for each crate on [docs.rs](https://docs.rs/).\n\n## Getting Started\n\n### Prerequisites\n\n- Ensure you have Docker Compose installed. If not, you can download it from [Docker Desktop](https://www.docker.com/products/docker-desktop).\n\n### Setup\n\n1. **Environment Variables**: Copy the sample environment file and configure the variables.\n\n    ```bash\n    cp env.example .env\n    ```\n\n2. **Docker Compose**: Start the Docker containers.\n\n    ```bash\n    docker compose up -d\n    ```\n3. **Upload Postman Collection**: Open up Postman locally via the desktop client. Then upload the file entitled `Web Service Tutorial.postman_collection.json`. You should now have access to the Postman collection.\n4. **Get a Bearer Token**:\n    1. Go to the `create_user` route under the `auth` folder.\n    2. Create a user by hitting the `Send` button. If there's a problem, change both the username and password.\n    3. After you have successfully created a new user, check the headers. Under the `authorization` header, you should see the bearer token. Copy everything after where it says `Bearer`.\n    4. Now click on the `Web Service Tutorial` Postman collection.\n    5. Under the `Authorization` page, you should see a `Type` dropdown.\n    6. Select `Bearer Token`. After you select `Bearer Token`, underneath should apear another dropdown that says `Token`. Paste the copied bearer token here from before. You should now be authorized for four hours, or for however long `JWT_HOURS_ACTIVE` is set to in your .env file.\n    7. If you have any issues hitting the routes, try changing every `localhost:8080` to `http://127.0.0.1:8080`\n\n6. **Test Routes**: Open your browser or use a tool like Postman to hit the following route:\n\n    ```\n    http://127.0.0.1:8080/blog\n    ```\n\n### Database GUI (PgAdmin4)\n\n- Access the PgAdmin4 interface at `http://localhost:16543`.\n- Username: `test@test.com`\n- Password: `test`\n\nFor detailed instructions on adding a PostgreSQL server in PgAdmin4, refer to the [PG Admin guide](https://onexlab-io.medium.com/docker-compose-postgres-initdb-ba0021deef76).\n\n### SQL Schema\n\nThe `init.sql` file contains the SQL statements that define the database schema. Feel free to explore it to understand the database structure.\n\n### Authentication\n\nThe `SKIP_AUTH` environment variable controls JWT authentication. Set it to `true` to disable JWT during development.\n\n## Additional Resources\n\n- [Crates.io Package](https://crates.io/crates/webservice_tutorial)\n- [PG Admin Guide](https://onexlab-io.medium.com/docker-compose-postgres-initdb-ba0021deef76)\n- Medium Post: [Creating a Web Service in Rust with Actix-Web, SQLx, and PostgreSQL](https://hstreet.tech/creating-a-web-service-in-rust-with-actix-web-sqlx-and-postgresql-805c9d1aae35)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharrisonhemstreet%2Fwebservice_tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharrisonhemstreet%2Fwebservice_tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharrisonhemstreet%2Fwebservice_tutorial/lists"}