{"id":20783364,"url":"https://github.com/james-flynn-ie/hello-rest-api","last_synced_at":"2026-04-05T23:32:18.526Z","repository":{"id":189803364,"uuid":"679364971","full_name":"james-flynn-ie/hello-rest-api","owner":"james-flynn-ie","description":"Hello World REST API written in Python Flask. Terraform code for deploying the environment as a Docker container is also included.","archived":false,"fork":false,"pushed_at":"2023-08-22T14:50:09.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-18T09:27:04.336Z","etag":null,"topics":["docker","flask","github-actions","pytest","python","terraform"],"latest_commit_sha":null,"homepage":"","language":"Python","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/james-flynn-ie.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":"2023-08-16T17:11:04.000Z","updated_at":"2023-08-22T15:21:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"70688daa-6351-4512-8054-169701b8a79e","html_url":"https://github.com/james-flynn-ie/hello-rest-api","commit_stats":null,"previous_names":["james-flynn-ie/hello-rest-api"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james-flynn-ie%2Fhello-rest-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james-flynn-ie%2Fhello-rest-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james-flynn-ie%2Fhello-rest-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james-flynn-ie%2Fhello-rest-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/james-flynn-ie","download_url":"https://codeload.github.com/james-flynn-ie/hello-rest-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243125552,"owners_count":20240276,"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":["docker","flask","github-actions","pytest","python","terraform"],"created_at":"2024-11-17T14:18:26.538Z","updated_at":"2025-12-30T22:52:57.581Z","avatar_url":"https://github.com/james-flynn-ie.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hello Rest API\n\n[![hello-rest-api lint and test](https://github.com/james-flynn-ie/hello-rest-api/actions/workflows/main.yml/badge.svg)](https://github.com/james-flynn-ie/hello-rest-api/actions/workflows/main.yml)\n\nA Flask web App that contains two endpoints.\n\n- /api/v1/hello: Returns round-robin responses\n- /api/v1/handshake: Demonstrates the use of basic authentication.\n\n## Requirements\n\n- Python v3.11\n- Docker\n- Terraform\n- AZ CLI\n- Azure subscription\n\n## Use VirtualEnv\n\nVirtualenv is used to isolate Python environments. For more information, see the [virtualenv docs](https://virtualenv.pypa.io/en/stable/)\n\nTo set up virtualenv (for Windows/Git Bash):\n\n```\npip install virtualenv\n\ncd \u003cproject root directory\u003e\npython -m virtualenv venv\n\n# On Windows PowerShell:\n.\\venv\\Scripts\\activate\n# Or on Git Bash:\nsource ./venv/Scripts/activate\n```\n\n## Run the application locally\n\nTo launch the Flask web server, run the following commands:\n\n```\npip install -r requirements.txt\npython hello_rest_api/app.py\n```\n\n## Testing \n\n### Testing the \"hello\" endpoint\n\nEnter the URL http://127.0.0.1:5000/api/v1/hello in a browser to view the Hello World page. \nRefreshing the browser should alternate the response between \"hello\" and \"Hello from new v1\".\n\n### Testing the \"handshake\" endpoint\n\nThe handshake endpoint has basic authentication on place.\n\nUse the following cURL command to access the handshake endpoint with Admin RBAC privileges:\n\n```\ncurl --request POST --user \"admin:admin_password\" --url http://127.0.0.1:5000/api/v1/handshake\n```\n\n\nUse the following cURL command to return a 403 Forbidden message for a user without admin RBAC privileges:\n\n```\ncurl --request POST --user \"user:user_password\" --url http://127.0.0.1:5000/api/v1/handshake\n```\n\nNote that a 401 Unauthorized response will be returned if no username and password are sent:\n\n```\ncurl --request POST --url http://127.0.0.1:5000/api/v1/handshake\n```\n\n### Linting\n\nLinted using PyLint, MyPy and Flake8.\n\n## Docker\n\n### Test container\n\nRun the following command to build the container:\n\n```\ndocker build hello-rest-api:latest .\n```\n\nStart the container locally using the command:\n\n```\ndocker run -p 80:5000 hello-rest-api:latest\n```\n\nOpen a browser to access the hello endpoint.\n\n```\nhttp://localhost/api/v1/hello\n```\n\nThe handshake API can be reached through cURL, run from a different terminal:\n\n```\ncurl --request POST --user \"admin:admin_password\" http://127.0.0.1/api/v1/handshake \n```\n\n### Push container to Azure Container Registry (ACR)\n\nTo push a container to ACR, first tag the build with the ACR's Fully Qualified Domain Name:\n\n```\ndocker build -t \u003c\u003cname-of-acr\u003e\u003e.azurecr.io/hello-rest-api:latest .\n\ndocker push \u003c\u003cname-of-acr\u003e\u003e.azurecr.io/hello-rest-api:latest\n```\n\n## Terraform\n\nTerraform is an infrastructure as code tool that lets you build, change, and version cloud resources safely and efficiently. \n\nThe scripts are broken into two phases for deployment:\n\n- 01-acr: Contains the resource group and ACR that are required for the App service to be deployed.\n- 02-app-service: Contains the App Service Plan and Web App that will host the application.\n\n### Commands\n\n```\ncd terraform\n\n# Download Terraform providers\nterraform init\n\n# Check syntax\nterraform validate\n\n# Check plan (For production use, it is recommended to save the file using `-out` and use it in the apply stage)\nterraform plan\n\n# Deploy the infrastructure\nterraform apply\n\n# Destroy the infrastructure\nterraform apply -destroy\n```\n\n### Test the App Service\n\n#### Hello API endpoint\n\nOpen a browser to access the hello endpoint.\n\n```\nhttps://\u003c\u003cname-of-web-app\u003e\u003e.azurewebsites.net/api/v1/hello\n```\n\n#### Handshake API endpoint\n\nTo access the web-app's handshake endpoint, run the following command.:\n\n```\ncurl --request POST --user \"admin:admin_password\" --url https://\u003c\u003cname-of-web-app\u003e\u003e.azurewebsites.net/api/v1/handshake\n```\n\n## Github Actions Workflow\n\nGithub Actions workflow will lint and test code on each push. \n\nPushes to main will deploy the Docker container on an App Service.\n\n### Requirements for Deploying an Azure App Service\n\n- Azure Managed Identity with:\n  - (Federated credentials)[https://github.com/marketplace/actions/azure-login#configure-a-federated-credential-to-use-oidc-based-authentication] linked to Github Actions.\n    - AZURE_CLIENT_ID\n    - AZURE_TENANT_ID\n    - AZURE_SUBSCRIPTION_ID\n  - Permissions to deploy an App Service within the resource group or subscription.\n  - Credentials stored as (secrets)[https://docs.github.com/en/actions/security-guides/encrypted-secrets] in Github Actions.\n\n- Terraform Backend:\n  - Azure Storage Account with:\n    - SAS token\n    - Resource Group Name\n    - Container Name\n    - Key name (Name of TF State file within container)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjames-flynn-ie%2Fhello-rest-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjames-flynn-ie%2Fhello-rest-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjames-flynn-ie%2Fhello-rest-api/lists"}