Skip to content

Commit

Permalink
Create HTTPResponse resource
Browse files Browse the repository at this point in the history
  • Loading branch information
campb303 committed Jul 12, 2021
1 parent e605dba commit c7ffe21
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/webqueue2api/api/resources/http_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from flask_restful import Resource
from http import HTTPStatus



class HTTPResponse(Resource):
def get(self, response_code: int) -> tuple:
"""Returns the passed HTTP response code and a JSON payload containing a description of the response.
Args:
error_code (int): The HTTP response to return.
Returns:
tuple: HTTP response descriptions as JSON and HTTP response code.
"""
# Build list of HTTP responses from http library
responses = {}
for status in HTTPStatus:
responses[status.value] = status.phrase

# Check for requested response code in reponses
if response_code not in responses.keys():
return ({"message": f"No entry for response code {response_code} found."}, 404)

return ({"message": f"{responses[response_code]}"}, response_code)

0 comments on commit c7ffe21

Please sign in to comment.