Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
HTTP status code responses with predefined or custom messages for easy integration into web applications and APIs.
A Python package that provides functions for HTTP status codes, allowing you to easily generate responses with predefined or custom messages. This package is useful for handling API responses in web development.
You can install the package using pip:
pip install status-codes
You can use the functions from the status_codes package to get HTTP responses with status codes, messages, and data.
from status_codes import StatusCodes
response = StatusCodes.ok_200()
print(response) # Outputs: {'status': 200, 'message': 'Request succeeded.'}
response = StatusCodes.ok_200(custom_message="Custom success message")
print(response) # Outputs: {'status': 200, 'message': 'Custom success message'}
response = StatusCodes.ok_200(data={"key": "value"})
print(response) # Outputs: {'status': 200, 'message': 'Request succeeded.', 'data': {'key': 'value'}}
response = StatusCodes.ok_200(custom_message="Custom success message", data={"key": "value"})
print(response) # Outputs: {'status': 200, 'message': 'Custom success message', 'data': {'key': 'value'}}
Here is a list of the available status code functions, each with optional custom_message
and data
parameters:
continue_100(custom_message=None, data=None)
switching_protocols_101(custom_message=None, data=None)
processing_102(custom_message=None, data=None)
early_hints_103(custom_message=None, data=None)
ok_200(custom_message=None, data=None)
created_201(custom_message=None, data=None)
accepted_202(custom_message=None, data=None)
non_authoritative_information_203(custom_message=None, data=None)
no_content_204(custom_message=None, data=None)
reset_content_205(custom_message=None, data=None)
partial_content_206(custom_message=None, data=None)
multi_status_207(custom_message=None, data=None)
already_reported_208(custom_message=None, data=None)
im_used_226(custom_message=None, data=None)
multiple_choices_300(custom_message=None, data=None)
moved_permanently_301(custom_message=None, data=None)
found_302(custom_message=None, data=None)
see_other_303(custom_message=None, data=None)
not_modified_304(custom_message=None, data=None)
use_proxy_305(custom_message=None, data=None)
temporary_redirect_307(custom_message=None, data=None)
permanent_redirect_308(custom_message=None, data=None)
bad_request_400(custom_message=None, data=None)
unauthorized_401(custom_message=None, data=None)
payment_required_402(custom_message=None, data=None)
forbidden_403(custom_message=None, data=None)
not_found_404(custom_message=None, data=None)
method_not_allowed_405(custom_message=None, data=None)
not_acceptable_406(custom_message=None, data=None)
proxy_authentication_required_407(custom_message=None, data=None)
request_timeout_408(custom_message=None, data=None)
conflict_409(custom_message=None, data=None)
gone_410(custom_message=None, data=None)
length_required_411(custom_message=None, data=None)
precondition_failed_412(custom_message=None, data=None)
payload_too_large_413(custom_message=None, data=None)
uri_too_long_414(custom_message=None, data=None)
unsupported_media_type_415(custom_message=None, data=None)
range_not_satisfiable_416(custom_message=None, data=None)
expectation_failed_417(custom_message=None, data=None)
im_a_teapot_418(custom_message=None, data=None)
misdirected_request_421(custom_message=None, data=None)
unprocessable_content_422(custom_message=None, data=None)
locked_423(custom_message=None, data=None)
failed_dependency_424(custom_message=None, data=None)
too_early_425(custom_message=None, data=None)
upgrade_required_426(custom_message=None, data=None)
precondition_required_428(custom_message=None, data=None)
too_many_requests_429(custom_message=None, data=None)
request_header_fields_too_large_431(custom_message=None, data=None)
unavailable_for_legal_reasons_451(custom_message=None, data=None)
internal_server_error_500(custom_message=None, data=None)
not_implemented_501(custom_message=None, data=None)
bad_gateway_502(custom_message=None, data=None)
service_unavailable_503(custom_message=None, data=None)
gateway_timeout_504(custom_message=None, data=None)
http_version_not_supported_505(custom_message=None, data=None)
variant_also_negotiates_506(custom_message=None, data=None)
insufficient_storage_507(custom_message=None, data=None)
loop_detected_508(custom_message=None, data=None)
not_extended_510(custom_message=None, data=None)
network_authentication_required_511(custom_message=None, data=None)
Each function in the StatusCodes class allows you to pass optional custom_message
and data
parameters. If no custom_message
is provided, the function uses the default message associated with the status code. If data
is not provided, no additional data will be included in the response.
response = StatusCodes.bad_request_400(custom_message="Custom bad request message")
print(response)
# Outputs: {'status': 400, 'message': 'Custom bad request message'}
response = StatusCodes.bad_request_400(data={"key": "value"})
print(response)
# Outputs: {'status': 400, 'message': 'Bad request syntax.', 'data': {'key': 'value'}}
response = StatusCodes.bad_request_400(custom_message="Custom bad request message", data={"key": "value"})
print(response)
# Outputs: {'status': 400, 'message': 'Custom bad request message', 'data': {'key': 'value'}}
response = StatusCodes.bad_request_400()
print(response)
# Outputs: {'status': 400, 'message': 'Bad request syntax.'}
custom_message
and data
must be passed as keyword arguments. Positional arguments are not supported for these parameters.FAQs
HTTP status code responses with predefined or custom messages for easy integration into web applications and APIs.
We found that status-codes demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.