{"id":39075710,"url":"https://github.com/cloud-gov/pages-example-website-api","last_synced_at":"2026-01-17T18:26:31.117Z","repository":{"id":210963310,"uuid":"727864031","full_name":"cloud-gov/pages-example-website-api","owner":"cloud-gov","description":null,"archived":false,"fork":false,"pushed_at":"2025-10-02T18:25:56.000Z","size":82,"stargazers_count":1,"open_issues_count":3,"forks_count":1,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-10-02T20:30:03.862Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloud-gov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-12-05T18:24:55.000Z","updated_at":"2025-10-02T18:26:01.000Z","dependencies_parsed_at":"2023-12-11T23:06:32.214Z","dependency_job_id":"435a122b-6cb8-47ef-b54a-bf94bae1f677","html_url":"https://github.com/cloud-gov/pages-example-website-api","commit_stats":null,"previous_names":["ephraim-g/cfpyapi","cloud-gov/pages-example-website-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cloud-gov/pages-example-website-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud-gov%2Fpages-example-website-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud-gov%2Fpages-example-website-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud-gov%2Fpages-example-website-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud-gov%2Fpages-example-website-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloud-gov","download_url":"https://codeload.github.com/cloud-gov/pages-example-website-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud-gov%2Fpages-example-website-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28515471,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T17:57:59.192Z","status":"ssl_error","status_checked_at":"2026-01-17T17:57:52.527Z","response_time":85,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2026-01-17T18:26:31.018Z","updated_at":"2026-01-17T18:26:31.090Z","avatar_url":"https://github.com/cloud-gov.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Pages](/assets/images/pages-logo.png)\n\n![Static Badge](https://img.shields.io/badge/Python-3776AB?style=for-the-badge\u0026logo=python\u0026logoColor=white)\n![Static Badge](https://img.shields.io/badge/Flask-000000?style=for-the-badge\u0026logo=flask\u0026logoColor=white)\n\n\n# API Application\n\n## Intro\n\nThis python flask application provides a way to interact with a PostgreSQL database by providing a secure connection using Cloud Foundry environment variables and return the result as JSON to a static website hosted on Pages. \n\n**Functions**\n\n- Connect to the RDS service instance\n- Access the database \n- Execute a SQL query\n- Fetch data from the database\n- Return the result as JSON\n\n## Where to input your own data\n\nThere are a few instances in the `app.py` and the `manifest.yml` file where you will need to inject your own data that is specific to your project/work.\n\nIn `app.py`\n\nLine 14: `CORS(app, origins=['https://your-pages-url'], headers=['Content-Type'], methods=['GET'])`\n\u003cbr\u003e\n*when launching the application for the first time this line can be ommitted until you are ready for your Pages site to hit the API endpoint*\n\u003cbr\u003e\n\nLine 11: `port = int(os.getenv('PORT', {whatever port you wish to expose})`\n\nLine 17: `aws_rds = app_env.get_service(name='your-db-name')`\n\n\u003cbr\u003e\n\n*Optional if you wish to serve from the root URL or not*\n\n\u003cbr\u003e\n\nLine 56: `@app.route('/', methods=['GET'])`\n\nLine 69: `@app.route('/your_sub_route', methods=['GET'])`\n\nLine 66: `query = 'SELECT * FROM {your_table} LIMIT 15'`\n\nIn `manifest.yml`\n\nLine 3: `- name: your_app_name`\n\nLine 14: `- {your_db_name}`\n\n## Set Up\n\n### Prequesites\n- Pages [sandbox](https://cloud.gov/pages/documentation/sandbox/) or existing account.\n- Pages [site](https://github.com/Ephraim-G/Data-table) to display the data.\n*the site repository linked is the example site created in conjunction for and with this application, feel free to utilize that one for testing purposes or create your own.*\n- [Cloud Foundry CLI](https://docs.cloudfoundry.org/cf-cli/install-go-cli.html)\n- [Cloud Foundry CLI Service Connection Plugin](https://github.com/cloud-gov/cf-service-connect)\n- cloud.gov [sandbox](https://cloud.gov/docs/pricing/free-limited-sandbox/#sandbox-limitations) or existing account with the following security groups applied `trusted_local_networks_egress` and `public-egress`.\n- [PostgrSQL v15 database](https://cloud.gov/docs/services/relational-database/#create-an-instance) within cloud.gov.\n- Dataset to `COPY` into the PostgreSQL database\n*for this example we used a CSV file from [data.gov](https://catalog.data.gov/dataset/?q=\u0026sort=views_recent+desc\u0026ext_location=\u0026ext_bbox=\u0026ext_prev_extent=\u0026_res_format_limit=0).\n- [Python](https://www.python.org/downloads/) or download via [Homebrew](https://docs.brew.sh/Homebrew-and-Python).\n- [pip](https://pypi.org/project/pip/) \n\n## Implementation\n\n1. Login to cloud.gov via the terminal with `cf login -a api.fr.cloud.gov --sso`.\n2. Follow the cloud.gov [documentation](https://cloud.gov/docs/services/relational-database/#create-an-instance) to provision a `aws-rds` `micro-psql` database instance.\n3. Via the CF service connection plugin connect to your databse and [create](https://www.postgresql.org/docs/current/tutorial-table.html) a table with column(s) containing the proper headers according to your CSV file dataset.\n4. [Import](https://www.postgresqltutorial.com/postgresql-tutorial/import-csv-file-into-posgresql-table/) the CSV file into the created table.\n5. Fork this repository and clone it directly to your machine.\n6. Move into the forked repository with `cd /path/to/forked/repository`.\n7. In whatever IDE of your choice input your own specific data where applicable.\n7. Run `pip install -r requirements.txt` to install the necessary modules.\n8. Deploy the app into your space with `cf push`.\n9. Verify that the application is in the space with `cf apps`.\n\n*To bind via the CLI instead of using the manifest.yml file*\n1. [Bind](https://docs.cloudfoundry.org/devguide/services/application-binding.html#bind) the application to the RDS service instance previously provisioned with the cf CLI.\n2. Redeploy the application with `cf restart app-name`.\n\n# Development\n\n## Run mock API test locally via Docker\n\n### Prerequisites\n\n- **Docker and Docker Compose** (v20.10.0+)\n- **Python 3.8+**\n- **pip**\n\n### Dependencies\n\nAll required packages are listed in the `requirements.txt` file.\n\n## Getting Started\n\n### Install Dependencies\n\nInstall required Python packages:\n\n`pip install requirements.txt`\n\n### Setup Test Database\n\nRun the database setup script to create a Docker container with PostgreSQL and seed it with mock data.\n\n`./test-db.sh`\n\nThis script will:\n\n- Build and start Docker containers\n- Initialize the PostgreSQL database\n- Create a users table\n- Populate the table with 10 mock users\n\n### Run Tests\n\nExecute the test via pytest:\n\n`pytest test.py -v`\n\nThe test will:\n\n- Execute a mock HTTP request to the FastAPI endpoint\n- Verify the connection to the PostgreSQL database works correctly\n- Validate the returned user data matches the expected format\n\n## Troubleshooting\n\n- **Database Connection Issues**: Ensure Docker containers are running with `docker ps`\n- **Port Conflicts**: Check if port 5432 is already in use\n- **Permission Denied**: You may need to make the `test-db.sh` script executable with `chmod +x test-db.sh`\n\n## Cleanup\n\nTo stop and remove the Docker containers:\n\n`docker compose down`\n\n \n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloud-gov%2Fpages-example-website-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloud-gov%2Fpages-example-website-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloud-gov%2Fpages-example-website-api/lists"}