{"id":23413907,"url":"https://github.com/erdem/flask-restful-example","last_synced_at":"2025-04-12T05:50:31.581Z","repository":{"id":45123156,"uuid":"199344698","full_name":"erdem/flask-restful-example","owner":"erdem","description":"A RESTful contact API implementation with using Flask SQLAlchemy, PyTest, Marshmallow and Celery.","archived":false,"fork":false,"pushed_at":"2022-01-06T22:36:07.000Z","size":26,"stargazers_count":35,"open_issues_count":2,"forks_count":11,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-06T06:12:13.054Z","etag":null,"topics":["celery","celerybeat","flask","flask-sqlalchemy","marshmallow","pytest","restful-api","sqlalchemy"],"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/erdem.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}},"created_at":"2019-07-28T22:49:02.000Z","updated_at":"2024-07-17T04:20:23.000Z","dependencies_parsed_at":"2022-09-05T08:41:56.512Z","dependency_job_id":null,"html_url":"https://github.com/erdem/flask-restful-example","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/erdem%2Fflask-restful-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erdem%2Fflask-restful-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erdem%2Fflask-restful-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erdem%2Fflask-restful-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erdem","download_url":"https://codeload.github.com/erdem/flask-restful-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248525153,"owners_count":21118616,"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":["celery","celerybeat","flask","flask-sqlalchemy","marshmallow","pytest","restful-api","sqlalchemy"],"created_at":"2024-12-22T19:56:06.347Z","updated_at":"2025-04-12T05:50:31.552Z","avatar_url":"https://github.com/erdem.png","language":"Python","readme":"Flask Example\n=============\n\nThis repository contains the example code for a contact API project, using SQLAlchemy, PyTest, Celery with Flask.\n\n\n### Tasks\n- Model a Contact with username, email, first name and surname.\n- Create a Restful API that returns a list of all contacts.\n- Returns a contact by username.\n- Saves a Contact.\n- Updates a Contact\n- Deletes a Contact\n- Allow a contact to have multiple email addresses.  Adjust GET, POST, PUT, DEL methods to the new sub entity.\n- Extend the GET to also accept the email address for contact retrieval.\n- Implement a celery task to create a random contact with two email addresses every 15 seconds. Any older entries then 1 min should be cleaned up and deleted.\n\n\nSetup\n-----\n\n1. Clone this repository.\n2. Create a virtualenv and activate.\n3. Install requirement packages. \n4. Make sure `redis-server` running on background.\n5. Set `FLASK_ENV` environment variable as `development`. (`export FLASK_ENV=development`)\n6. Open a second terminal and start celery: `celery worker -A celery_worker.celery --loglevel=info`.\n7. Open a third terminal and start celery-beat: `celery -A celery_worker:celery beat --loglevel=INFO`.\n8. Start the Flask application on your original terminal window: `flask run`.\n9. Go to `http://localhost:5000/api/contacts/` and enjoy!\n\n\u003e You can run the tests with `pytest tests` command.\n\nSome example usage for Contact API\n----------------------------------\n\n##### Creating a contact entity \n\n```bash\ncurl -X POST \\\n  http://localhost:5000/api/contacts/ \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n\t\"username\": \"admin\",\n\t\"first_name\": \"Armin\",\n\t\"last_name\": \"Ronacher\",\n\t\"emails\": [\n\t\t{\"email\": \"arminronacher@mail.com\"}\n\t]\n}'\n```\n\n##### Updating a contact entity \n\n```bash\ncurl -X PATCH \\\n  http://localhost:5000/api/contacts/admin/ \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n\t\"emails\": [\n\t\t{\"email\": \"admin@mail.com\"}\n\t]\n}'\n```\n\n##### Get list of contacts by username\n\n```bash\ncurl -X GET http://localhost:5000/api/contacts/admin/\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferdem%2Fflask-restful-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferdem%2Fflask-restful-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferdem%2Fflask-restful-example/lists"}