{"id":16452858,"url":"https://github.com/vitalk/flask-apify","last_synced_at":"2025-03-23T10:31:53.188Z","repository":{"id":19477655,"uuid":"22723145","full_name":"vitalk/flask-apify","owner":"vitalk","description":"The Flask extension to create an API to your application as a ninja","archived":false,"fork":false,"pushed_at":"2016-08-14T20:09:08.000Z","size":77,"stargazers_count":7,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-18T19:38:01.146Z","etag":null,"topics":["api","flask","rest"],"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/vitalk.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":"2014-08-07T13:57:42.000Z","updated_at":"2019-05-02T10:57:39.000Z","dependencies_parsed_at":"2022-09-26T22:11:33.589Z","dependency_job_id":null,"html_url":"https://github.com/vitalk/flask-apify","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalk%2Fflask-apify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalk%2Fflask-apify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalk%2Fflask-apify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalk%2Fflask-apify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vitalk","download_url":"https://codeload.github.com/vitalk/flask-apify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245090703,"owners_count":20559296,"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":["api","flask","rest"],"created_at":"2024-10-11T10:14:00.468Z","updated_at":"2025-03-23T10:31:52.723Z","avatar_url":"https://github.com/vitalk.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Flask-Apify\n===========\n\nThe Flask extension to create an API to your application as a ninja.\n\nQuickstart\n----------\n\n```python\nfrom itertools import count\n\nfrom flask import Flask, request\nfrom flask_apify import Apify\nfrom flask_apify.exc import ApiNotFound\n\n\napp = Flask(__name__)\napify = Apify(url_prefix='/api/v1')\napify = apify.init_app(app)\n\nmytodos = {}\nnext_todo_id = count().next\n\n\ndef abort_if_todo_doesnot_exists(todo_id):\n    if todo_id not in mytodos:\n        raise ApiNotFound('Todo does not exists')\n\n\n@apify.route('/todos', methods=('GET',))\ndef todos():\n    '''Returns all todos.'''\n    return mytodos\n\n\n@apify.route('/todos', methods=('POST',))\ndef addtodo():\n    '''Create new todo.'''\n    todo_id = next_todo_id()\n    mytodos[todo_id] = request.form['todo']\n    return {todo_id: mytodos[todo_id]}, 201\n\n\n@apify.route('/todos/\u003cint:todo_id\u003e', methods=('DELETE',))\ndef rmtodo(todo_id):\n    '''Remove todo.'''\n    abort_if_todo_doesnot_exists(todo_id)\n    del mytodos[todo_id]\n    return None, 204\n\n\n@apify.route('/todos/\u003cint:todo_id\u003e', methods=('GET',))\ndef todo(todo_id):\n    abort_if_todo_doesnot_exists(todo_id)\n    return {todo_id: mytodos[todo_id]}\n\n\n# important to register all added routes to an application\napp.register_blueprint(apify.blueprint)\n\n\nif __name__ == '__main__':\n    app.run(debug=True)\n```\n\nUsage example\n-------------\n\nSave the example above somewhere, for example to `apify.py` and launch it.\n\n```sh\n$ python apify.py\n * Running on http://127.0.0.1:5000/\n * Restarting with reloader\n```\n\nThen test it in your command prompt.\n\nAdd a new todo:\n\n```sh\n$ curl -i http://localhost:5000/api/v1/todos -X POST \\\n-H \"Accept: application/json\" \\\n-d \"todo=Write documentation\"\n\nHTTP/1.0 201 CREATED\nContent-Type: application/json\n\n{\"0\": \"Write documentation\"}\n```\n\n```sh\n$ curl -i http://localhost:5000/api/v1/todos -X POST \\\n-H \"Accept: application/json\" \\\n-d \"todo=Publish to Github\"\n\nHTTP/1.0 201 CREATED\nContent-Type: application/json\n\n{\"1\": \"Publish to Github\"}\n```\n\nGet a todo list:\n\n```sh\n$ curl -i http://localhost:5000/api/v1/todos \\\n-H \"Accept: application/json\"\n\nHTTP/1.0 200 OK\nContent-Type: application/json\n\n{\"0\": \"Write documentation\", \"1\": \"Publish to Github\"}\n```\n\nGet a single todo:\n\n```sh\n$ curl -i http://localhost:5000/api/v1/todos/1 \\\n-H \"Accept: application/json\"\n\nHTTP/1.0 200 OK\nContent-Type: application/json\n\n{\"1\": \"Publish to Github\"}\n```\n\nDelete a todo:\n\n```sh\n$ curl -i http://localhost:5000/api/v1/todos/1 -X DELETE \\\n-H \"Accept: application/json\"\n\nHTTP/1.0 204 NO CONTENT\nContent-Type: application/json\n```\n\nError example:\n\n```sh\n$ curl -i http://localhost:5000/api/v1/todos/1 \\\n-H \"Accept: application/json\"\n\nHTTP/1.0 404 NOT FOUND\nContent-Type: application/json\n\n{\"error\": \"Not Found\", \"message\": \"Todo does not exists\"}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitalk%2Fflask-apify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvitalk%2Fflask-apify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitalk%2Fflask-apify/lists"}