{"id":17349053,"url":"https://github.com/gwali-1/restful","last_synced_at":"2026-05-19T07:33:29.526Z","repository":{"id":41312253,"uuid":"508655181","full_name":"Gwali-1/Restful","owner":"Gwali-1","description":"A rest api implementation using flask , flask restful and redis","archived":false,"fork":false,"pushed_at":"2022-07-01T14:40:15.000Z","size":35,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-05T21:50:08.007Z","etag":null,"topics":["api","flask","python","rest-api"],"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/Gwali-1.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":"2022-06-29T11:01:43.000Z","updated_at":"2022-08-31T12:30:18.000Z","dependencies_parsed_at":"2022-08-19T01:20:06.149Z","dependency_job_id":null,"html_url":"https://github.com/Gwali-1/Restful","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Gwali-1/Restful","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gwali-1%2FRestful","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gwali-1%2FRestful/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gwali-1%2FRestful/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gwali-1%2FRestful/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gwali-1","download_url":"https://codeload.github.com/Gwali-1/Restful/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gwali-1%2FRestful/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33206320,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-19T07:16:55.748Z","status":"ssl_error","status_checked_at":"2026-05-19T07:16:54.366Z","response_time":58,"last_error":"SSL_read: 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":["api","flask","python","rest-api"],"created_at":"2024-10-15T16:54:31.332Z","updated_at":"2026-05-19T07:33:29.508Z","avatar_url":"https://github.com/Gwali-1.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# RESTFUL\n_This  is an implementation of rest api using flask and flask restful.This implementation makes use of redis which is an in memory data store._\n_Here it is used as a database to hold user auth details._\n_I used redis mainly because the data im working with is light weigth and a traditional relational database would be an overkill in my opinion._\n_With redis i store user information such as username and password(which is hashed) in a `redit hash` , which is a data type in redis where values are stored as key value pairs like a python dictionary._\n_Also user tokens generated are stored under a key which is an id with a expiration time. Tokens generated for users are under expiration time. Tokens are returned to users with the time they expire as well as the id which together with token is used for authentication to access endpoints which have a security layer._\n\n\nAttached to the repo is a couple of unit test written to test the various endpoints for this api.`test.py`.\nAll test passed succesfully at the time this was written.\nseveral imorovements could be added to this api implementaion, for example adding a time restriction to how many tokens could be requested by a particular account.\n\n* To run the tests\n```\n pytest test.py\n```\n\n\n\n\n## Installation\nAfter cloning the repo\n\n* set up a virtual environment\n* install requirements.txt \n\n```\n$ virtualenv venv\n$ source venv/bin/activate\n(venv) $ pip install -r requirements.txt\n\n```\n\nif you are on windows\n\n```\n$ virtualenv venv\n$ venv\\Scripts\\activate\n(venv) $ pip install -r requirements.txt\n\n```\n\n\n## Running The Server\n\n* to run the server\nmake sure you are in the project directory\n```\npython api.py\n```\n* from a different terminal window , you can then send request to the server running locally\n\n\n\n\n## Documentation For Api\n\n\n* GET /api/cats\n\nReturns a json object containing fields of cat names and information about them.\nOn success the status code 200 is returned. This endpoint doesnt require any authentication.\nOn failure status code 501 is returned indicating the resource could not be returned. This will most definitley be a server \nerror as no auth is required for this endpoint.\n\n\n\n\n* GET /api/cats/\u003cstring:cat_name\u003e\n\nReturns a json object with information for the the requested cat.\nOn success the status code is 200, a json object with fields  `status` equal to \"Ok\", `name` equal to cat name  and `info` which is a description of the cat is returned.\nOn failure, in a situation where there is no match for requested cat, status code 401 is returned. Also a json object is returned with fild `status` equal to \"Bad\"\nand `Description` with and error message.\n\n\n* POST /api/cats/add\n\nAdds a new cat with a description and returns the updated cat database.\nThe request body must be a json object that defines fields `name` and `info` . Fields are required!\n* The request body posted must be of form json or server won't process the request.\nOn success status code 200 is returned  together with a json object containing message that entry has been added. If name of cat already already exist it is updated and a message telling user so is sent back.\nOn failure, if  for some reason entry could not be added or an error while adding the entry, status code 501 is returned with a json object containing description of situation.\n\n\n\n\n\n* POST api/add_user\n\nAdds a new user and returns an generated id and token to be used as auth verification for endpoints that require authentication.\nThe request body must be a json object that defines fields `username` and `password`. Fields are required!\n* The request body posted must be of form json or server won't perform process\n* The username and password are stored and account created for user\nThe password is hashed first.\nOn success status code 200 is returned together with a json object containing generated id and token and expiration time for token in seconds.\nOn failure, in situations where username is already taken, a status code 401 is returned with a json object with a description of the situation.\nOn failure, when user account could not be created and user not added, status code 501 is returned with with a json object with a description of the situation.\n\n\n* POST api/verify_token\nReturns a json object with status of a token, whether active or expired\n* The request body posted must be of form json or server won't acknowledge request.\nThe request body must be a json object that defines fields `id` and `token`. Fields are required!\nOn success status code 200 is returned  together with a json object containing field `status` equal to `OK` , username of account and token status `Active`.\nOn failure , in situations where token is expired, a status code 200 is still returned with a json object with token status `Expired`.\n\n\n\n* POST api/resource\n\nReturns a json object with a `data` field on success.\nThis endpoint requires authentication hence request body posted must be of form json that defines fields `id` and `token` equal to auth details returned to user on creation of account(token and id).\nFields are required!\nOn success status code 200 is returned  together with a json object containing field `Data` and `status`(equal to `Ok`).\nOn failure, in situations where auth details provided are wrong or token is expired, a status code 401 is returned with a json object with a description of the situation.\n\n\n## Examples\n* The following requests are sent using curl\n\n\n* GET /api/cats\n\n```\ncurl -i -X  GET  http://127.0.0.1:5000/api/cats/\n\nHTTP/1.1 200 OK\nServer: Werkzeug/2.1.2 Python/3.10.4\nDate: Thu, 30 Jun 2022 20:13:01 GMT\nContent-Type: application/json\nContent-Length: 764\nConnection: close\n\n{\n    \"status\": \"Ok\",\n    \"Cats\": {\n        \"Devon-Rex-Cats\": \"\\n    The Devon Rex is a relatively newer breed of cats, discovered by accident in the region of Devonshire, England, in 1960 and has been called many things: a pixie cat,\\n    an alien cat, a cat that looks like an elf \\u2014 or a bat. It is also known to behave more like a dog than like a cat.\\n    \",\n        \"Abyssinian-Cats\": \"\\n    Abys, as they are lovingly called, are elegant and regal-looking, easy to care for and make ideal pets for cat lovers.\\n    Lively and expressive, with slightly wedge-shaped heads, half-cupped ears, medium length bodies and well-developed muscles,\\n    Abyssinians have long, slender legs and their coats are short and close-lying to their bodies\\n    \"\n    }\n}\n\n\n```\n\n* GET /api/cats/\u003cstring:cat_name\u003e\n```\ncurl -i -X  GET  http://127.0.0.1:5000/api/cats/Devon-Rex-Cats\n\nHTTP/1.1 200 OK\nServer: Werkzeug/2.1.2 Python/3.10.4\nDate: Thu, 30 Jun 2022 20:15:51 GMT\nContent-Type: application/json\nContent-Length: 359\nConnection: close\n\n{\n    \"status\": \"Ok\",\n    \"name\": \"Devon-Rex-Cats\",\n    \"info\": \"The Devon Rex is a relatively newer breed of cats, discovered by accident in the region of Devonshire, England, in 1960 and has been called many things: a pixie cat,\\n    an alien cat, a cat that looks like an elf \\u2014 or a bat. It is also known to behave more like a dog than like a cat.\"\n}\n\n```\n\n* POST /api/cats/add\n\n```\ncurl -i -X POST -H \"Content-Type: application/json\" -d '{\"name\":\"testcat\",\"info\":\"the best type of cats\"}' http://127.0.0.1:5000/api/cats/add\n\nHTTP/1.1 200 OK\nServer: Werkzeug/2.1.2 Python/3.10.4\nDate: Thu, 30 Jun 2022 21:18:01 GMT\nContent-Type: application/json\nContent-Length: 847\nConnection: close\n\n{\n    \"status\": \"Ok\",\n    \"Description\": \"Added Succesfuly\",\n    \"Cats\": {\n        \"Devon-Rex-Cats\": \"\\n    The Devon Rex is a relatively newer breed of cats, discovered by accident in the region of Devonshire, England, in 1960 and has been called many things: a pixie cat,\\n    an alien cat, a cat that looks like an elf \\u2014 or a bat. It is also known to behave more like a dog than like a cat.\\n    \",\n        \"Abyssinian-Cats\": \"\\n    Abys, as they are lovingly called, are elegant and regal-looking, easy to care for and make ideal pets for cat lovers.\\n    Lively and expressive, with slightly wedge-shaped heads, half-cupped ears, medium length bodies and well-developed muscles,\\n    Abyssinians have long, slender legs and their coats are short and close-lying to their bodies\\n    \",\n        \"testcat\": \"the best type of cats\"\n    }\n}\n```\n\n* POST api/add_user\n\n```\ncurl -i -X POST -H \"Content-Type: application/json\" -d '{\"username\":\"TestUserr\",\"password\":\"lemon street\"}' http://127.0.0.1:5000/api/add_user/\n\nHTTP/1.1 200 OK\nServer: Werkzeug/2.1.2 Python/3.10.4\nDate: Thu, 30 Jun 2022 21:28:45 GMT\nContent-Type: application/json\nContent-Length: 205\nConnection: close\n\n{\n    \"status\": \"Ok\",\n    \"Description\": \"User added successfully\",\n    \"auth\": {\n        \"id\": \"002d\",\n        \"token\": \"JJ6lG9A9oZsAgmu17am817X_wSrJkqNnm6w8ZHaLZhg\"\n    },\n    \"token expiration time\": 3600\n}\n\n```\n\n* For when username is taken\n\n```\nHTTP/1.1 401 UNAUTHORIZED\nServer: Werkzeug/2.1.2 Python/3.10.4\nDate: Thu, 30 Jun 2022 21:22:59 GMT\nContent-Type: application/json\nContent-Length: 80\nConnection: close\n\n{\n    \"status\": \"Bad\",\n    \"Description\": \"Username taken.Could not add user\"\n}\n```\n\n* POST api/verify_token\n\n\n```\ncurl -i -X POST -H \"Content-Type: application/json\" -d '{\"id\":\"002d\",\"token\":\"JJ6lG9A9oZsAgmu17am817X_wSrJkqNnm6w8ZHaLZhg\"}' http://127.0.0.1:5000/api/verify_token/ \n\nHTTP/1.1 200 OK\nServer: Werkzeug/2.1.2 Python/3.10.4\nDate: Thu, 30 Jun 2022 21:30:02 GMT\nContent-Type: application/json\nContent-Length: 71\nConnection: close\n\n{\n    \"status\": \"Ok\",\n    \"User\": \"TestUserr\",\n    \"Token\": \"Active\"\n}\n```\n* For when token is expires\n\n```\nHTTP/1.1 200 OK\nServer: Werkzeug/2.1.2 Python/3.10.4\nDate: Thu, 30 Jun 2022 21:24:43 GMT\nContent-Type: application/json\nContent-Length: 64\nConnection: close\n\n{\n    \"status\": \"Ok\",\n    \"User\": TestUserr,\n    \"Token\": \"Expired\"\n}\n\n```\n\n\n* POST api/resource\n\n```\ncurl -i -X POST -H \"Content-Type: application/json\" -d '{\"id\":\"002d\",\"token\":\"JJ6lG9A9oZsAgmu17am817X_wSrJkqNnm6w8ZHaLZhg\"}' http://127.0.0.1:5000/api/resource/\n\nHTTP/1.1 200 OK\nServer: Werkzeug/2.1.2 Python/3.10.4\nDate: Thu, 30 Jun 2022 21:31:59 GMT\nContent-Type: application/json\nContent-Length: 52\nConnection: close\n\n{\n    \"status\": \"Ok\",\n    \"data\": \"Good endpoint\"\n}\n```\n* For when auth details are wrong\n\n```\nHTTP/1.1 401 UNAUTHORIZED\nServer: Werkzeug/2.1.2 Python/3.10.4\nDate: Thu, 30 Jun 2022 21:32:51 GMT\nContent-Type: application/json\nContent-Length: 136\nConnection: close\n\n{\n    \"status\": \"Bad\",\n    \"Desccription\": \"Could not verify token and id. Check to see if token is still active or input is correct\"\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgwali-1%2Frestful","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgwali-1%2Frestful","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgwali-1%2Frestful/lists"}