{"id":25724051,"url":"https://github.com/masterivanic/fast-go-postgrestapi","last_synced_at":"2025-08-08T17:10:11.069Z","repository":{"id":279121891,"uuid":"937769374","full_name":"masterivanic/Fast-Go-PostgRestAPI","owner":"masterivanic","description":"API ready to be use made easily without a backend only PostgreDB \u0026 PostgRestServer standalone ","archived":false,"fork":false,"pushed_at":"2025-03-10T01:26:13.000Z","size":219,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-20T11:11:07.025Z","etag":null,"topics":["bash-script","postgresql","sql"],"latest_commit_sha":null,"homepage":"","language":"PLpgSQL","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/masterivanic.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,"zenodo":null}},"created_at":"2025-02-23T21:05:48.000Z","updated_at":"2025-06-17T03:03:44.000Z","dependencies_parsed_at":"2025-02-23T22:28:51.401Z","dependency_job_id":"0e7aacba-dadd-464e-8714-644097cdf7dd","html_url":"https://github.com/masterivanic/Fast-Go-PostgRestAPI","commit_stats":null,"previous_names":["masterivanic/fast-go-postgrestapi"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/masterivanic/Fast-Go-PostgRestAPI","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masterivanic%2FFast-Go-PostgRestAPI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masterivanic%2FFast-Go-PostgRestAPI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masterivanic%2FFast-Go-PostgRestAPI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masterivanic%2FFast-Go-PostgRestAPI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/masterivanic","download_url":"https://codeload.github.com/masterivanic/Fast-Go-PostgRestAPI/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masterivanic%2FFast-Go-PostgRestAPI/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269457772,"owners_count":24420289,"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-08-08T02:00:09.200Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","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":["bash-script","postgresql","sql"],"created_at":"2025-02-25T21:18:56.781Z","updated_at":"2025-08-08T17:10:11.057Z","avatar_url":"https://github.com/masterivanic.png","language":"PLpgSQL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fast \u0026 GO PostgRest API\n\nThis project demonstrates how to set up a RESTful API using **PostgREST** with a PostgreSQL database. The API allows you to manage `Users` and `Subjects` stored in the database.\n\n---\n\n## Table of Contents\n\n- [Overview](#overview)\n- [Prerequisites](#prerequisites)\n- [Setup](#setup)\n- [Database Schema](#database-schema)\n- [API Endpoints](#api-endpoints)\n- [Running the Project](#running-the-project)\n- [Testing the API](#testing-the-api)\n- [Troubleshooting](#troubleshooting)\n- [License](#license)\n\n---\n\n## Overview\n\nThis project uses:\n- **PostgreSQL** as the database.\n- **PostgREST** to automatically generate REST APIs from the database schema.\n- **Docker** to containerize the database and API.\n\nThe database schema includes two tables:\n- `api.User`: Stores user information.\n- `api.Subject`: Stores subjects associated with users.\n\n---\n\n## Prerequisites\n\nBefore running the project, ensure you have the following installed:\n\n- [Docker](https://docs.docker.com/get-docker/)\n- [Docker Compose](https://docs.docker.com/compose/install/)\n- [curl](https://curl.se/) (for testing the API)\n\n---\n\n## Setup\n\n1. **Clone the Repository**:\n   ```bash\n   git clone https://github.com/masterivanic/Fast-Go-PostgRestAPI.git\n   cd postgrest-demo\n   ```\n\n2. **Start the Services**:\n   Run the following command to start the PostgreSQL database and initialize the schema:\n   ```bash\n   docker-compose up -d\n   ```\n\n3. **Verify the Database**:\n   Ensure the database is running and initialized by checking the logs:\n   ```bash\n   docker logs pgrest-db-container\n   ```\n\n4. **Check DB logs**:\n   Verify db logging config work as weel\n    ```bash\n   docker logs pgrest-db-container \n   ```\n\n---\n\n## Database Schema\n\nThe database schema is defined in the `initdb/db.sql` file. It includes the following tables:\n\n### `api.User`\n- `user_id`: UUID (Primary Key)\n- `name`: Text (Not Null)\n- `address`: Text (Not Null)\n- `created_at`: Timestamp with Time Zone (Default: Current Time)\n- `updated_at`: Timestamp with Time Zone (Default: Current Time)\n\n### `api.Subject`\n- `subject_id`: UUID (Primary Key)\n- `label`: Text (Not Null)\n- `description`: Text\n- `average`: Float (Must be \u003e= 0)\n- `created_at`: Timestamp with Time Zone (Default: Current Time)\n- `user_id`: UUID (Foreign Key referencing `api.User`)\n\n---\n\n## API Endpoints\n\nPostgREST automatically generates RESTful endpoints based on the database schema. Below are the available endpoints:\n\n### Users\n- **GET** `/user`: Fetch all users.\n- **GET** `/user?select=name,address`: Fetch specific fields.\n- **POST** `/user`: Create a new user.\n- **PATCH** `/user?user_id=eq.{id}`: Update a user.\n- **DELETE** `/user?user_id=eq.{id}`: Delete a user.\n\n### Subjects\n- **GET** `/subject`: Fetch all subjects.\n- **GET** `/subject?select=label,description`: Fetch specific fields.\n- **POST** `/subject`: Create a new subject.\n- **PATCH** `/subject?subject_id=eq.{id}`: Update a subject.\n- **DELETE** `/subject?subject_id=eq.{id}`: Delete a subject.\n\n---\n\n## Running the Project\n\n0. **Create env file**:\n   ```bash\n   cp .env-example .env\n   ```\n\n1. **Start the Services**:\n   ```bash\n   docker-compose up -d\n   ```\n\n2. **Access the API**:\n   The API will be available at `http://localhost:3000`.\n\n3. **Test the API**:\n   Use `curl` or a tool like [Postman](https://www.postman.com/) to interact with the API.\n\n   Example:\n   ```bash\n   curl -i -X GET http://localhost:3000/user | jq '.'\n   ```\n\n---\n\n## Testing the API\n\n### Example Requests\n\n1. **Fetch All Users**:\n   ```bash\n   curl -i -X GET http://localhost:3000/user | jq '.'\n   ```\n\n2. **Create a New User**:\n   ```bash\n   curl -i -X POST http://localhost:3000/user \\\n       -H \"Authorization: Bearer token_generate_on_jwt_io_using_your_jwt_secret\" \\\n       -H \"Content-Type: application/json\" \\\n       -d '{\"name\": \"John Doe\", \"address\": \"123 Main St\"}'\n   ```\n\n3. **Fetch All Subjects**:\n   ```bash\n   curl -i -X GET http://localhost:3000/subject | jq '.'\n   ```\n\n4. **Create a New Subject**:\n   ```bash\n   curl -i -X POST http://localhost:3000/subject \\\n       -H \"Authorization: Bearer token_generate_on_jwt_io_using_your_jwt_secret\" \\\n       -H \"Content-Type: application/json\" \\\n       -d '{\"label\": \"Mathematics\", \"description\": \"Study of numbers\", \"average\": 85.5, \"user_id\": \"123e4567-e89b-12d3-a456-426614174000\"}'\n   ```\n\n5. **Check postgRest server config is same as you define**\n   ```bash\n   curl \"http://localhost:3001/config\" | jq '.'\n   ```\n\n6. **Print runtime schema cache**\n   ```bash\n   curl \"http://localhost:3001/schema_cache\"\n   ```\n---\n\n## Troubleshooting\n\n### Common Issues\n\n1. **Database Not Initialized**:\n   - Ensure the `initdb/db.sql` script is correctly mounted and executed.\n   - Check the logs for errors:\n     ```bash\n     docker logs pgrest-db-container\n     ```\n\n2. **API Not Responding**:\n   - Ensure the PostgREST service is running.\n   - Check the logs:\n     ```bash\n     docker logs postgrest-container\n     ```\n\n3. **Invalid JSON Response**:\n   - Ensure the API is returning valid JSON. Use `curl -i` to inspect the raw response.\n\n---\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n---\n\n## Grafana dashbord of Postregsql \u0026\u0026 PostgRest server \n![Alt text](/captures/grafana-dashboard.png?raw=true \"Postgresql \u0026 server dashboard\")\n\n## Acknowledgments\n\n- [PostgREST](https://postgrest.org/) for providing the REST API layer.\n- [PostgreSQL](https://www.postgresql.org/) for the powerful database backend.\n- [Docker](https://www.docker.com/) for containerization.\n- [Prometheus.exporter.postgres](https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.exporter.postgres/) - for collecting metrics from a PostgreSQL database.\n- [postgres-expoter-grafana](https://grafana.com/oss/prometheus/exporters/postgres-exporter/) - docs for postgres grafana dashboard\n\n---\n\nFeel free to contribute or report issues! 🚀\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasterivanic%2Ffast-go-postgrestapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmasterivanic%2Ffast-go-postgrestapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasterivanic%2Ffast-go-postgrestapi/lists"}